From 6e700157d02c1c1b22a615b69179189249c333eb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Oct 2022 11:51:17 +0000 Subject: [PATCH] [REM] core: odoo.modules.module.loaded flag Seems unnecessary, most of the information already lives in `sys.modules`. We can just check that. There are a few changes in behaviour, but they seem minor: - if post_load fails, subsequent attempts to load the module will "succeed" - since we didn't remove/reload the module, a failure because of an incorrect post_load wasn't fixable, however it was possible to update the manifest Still seems like a wonky state to be in, and one we should ignore. Also remove the logging of the error: since we're re-raising as-is, the parent logs it with a traceback, so this is unnecessary and redundant. closes odoo/odoo#103933 Signed-off-by: Xavier Morel (xmo) --- odoo/modules/module.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/odoo/modules/module.py b/odoo/modules/module.py index 5ff3a4ce3d3..0f3a7e6dd39 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -60,9 +60,6 @@ _DEFAULT_MANIFEST = { _logger = logging.getLogger(__name__) -# Modules already loaded -loaded = [] - class UpgradeHook(object): """Makes the legacy `migrations` package being `odoo.upgrade`""" @@ -368,27 +365,24 @@ def load_openerp_module(module_name): This is also used to load server-wide module (i.e. it is also used when there is no model to register). """ - global loaded - if module_name in loaded: + + qualname = f'odoo.addons.{module_name}' + if qualname in sys.modules: return try: - __import__('odoo.addons.' + module_name) + __import__(qualname) # Call the module's post-load hook. This can done before any model or # data has been initialized. This is ok as the post-load hook is for # server-wide (instead of registry-specific) functionalities. info = get_manifest(module_name) if info['post_load']: - getattr(sys.modules['odoo.addons.' + module_name], info['post_load'])() + getattr(sys.modules[qualname], info['post_load'])() - except Exception as e: - msg = "Couldn't load module %s" % (module_name) - _logger.critical(msg) - _logger.critical(e) + except Exception: + _logger.critical("Couldn't load module %s", module_name) raise - else: - loaded.append(module_name) def get_modules(): """Returns the list of module names