agritheory / test_utils

Common Test Utilities and Fixtures for AgriTheory Projects
4 stars 4 forks source link

`load_customizations` fails at `clear_global_cache()` if added in hooks `after_migrate` #73

Open MyuddinKhatri opened 2 months ago

MyuddinKhatri commented 2 months ago

load_customizations fails at clear_global_cache() if added in hooks after_migrate

If load_customizations from test_utils is executed from bench console then it runs fine.

     fn = 'approvals.customize.load_customizations'
  File "/home/user/Projects/frappe-bench/env/lib/python3.10/site-packages/test_utils/utils/customize.py", line 29, in load_customizations
    clear_global_cache()
      apps = ['frappe', 'erpnext', 'hrms', 'approvals']
      frappe_apps = ['frappe', 'erpnext', 'hrms', 'payments', 'lms', 'insights']
      app = 'approvals'
      customizations_directory = PosixPath('/home/user/Projects/frappe-bench/apps/approvals/approvals/approvals/custom')
  File "/home/user/Projects/frappe-bench/apps/frappe/frappe/cache_manager.py", line 113, in clear_global_cache
    frappe.setup_module_map()
      clear_website_cache = <function clear_website_cache at 0x7ff0d78c1870>
  File "/home/user/Projects/frappe-bench/apps/frappe/frappe/__init__.py", line 1554, in setup_module_map
    for module in get_module_list(app):
      _cache = RedisWrapper<ConnectionPool<Connection<host=127.0.0.1,port=13015,db=0>>>
      app = 'hrms'
      module = 'payment_gateways'
  File "/home/user/Projects/frappe-bench/apps/frappe/frappe/__init__.py", line 1394, in get_module_list
    return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
      app_name = 'hrms'
builtins.AttributeError: module 'hrms' has no attribute '__file__'
agritheory commented 2 months ago

@MyuddinKhatri What if we don't clear the cache? Are the schema definitions updated?

MyuddinKhatri commented 2 months ago

e? Are the schema definitions updated?

@agritheory I tried without clearing cache the scheme definitions got updated correctly. Can we remove clear_global_cache() and proceed OR take a look into why this is happening,

One more thing to be noted if I run bench --site <SITE_NAME> execute app.file.load_customizations then this runs without any error, it only fails if we add it in the after_migrate hook.