From 3fbd00d67cfa89a3c0e319ad659e88549b8052ec Mon Sep 17 00:00:00 2001 From: Jinane Maksoud Date: Tue, 24 Sep 2024 10:46:27 +0200 Subject: [PATCH] [IMP] util/modules: force install of new modules The method 'force_install_module' only works when the module already exists in the database and changes its state immediately. For new modules this does not work unless the module is explicitly added, or we use the auto discovery methods instead. --- src/util/modules.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/util/modules.py b/src/util/modules.py index 5edf8659..c30198f0 100644 --- a/src/util/modules.py +++ b/src/util/modules.py @@ -476,7 +476,7 @@ def _up(table, old, new): cr.execute("DELETE FROM ir_module_module_dependency WHERE name=%s", [old]) cr.execute("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s", [mod_ids[old]]) if state in INSTALLED_MODULE_STATES: - force_install_module(cr, into) + _force_install_module(cr, into) def force_install_module(cr, module, if_installed=None): @@ -486,8 +486,19 @@ def force_install_module(cr, module, if_installed=None): :param str module: name of the module to install :param list(str) or None if_installed: only force the install when these modules are already installed - :return str: the *original* state of the module """ + if version_gte("saas~14.5"): + # We must delay until the modules actually exists. They are added by the auto discovery process. + if not if_installed or modules_installed(cr, *if_installed): + ENVIRON["__modules_auto_discovery_force_installs"].add(module) + else: + _force_install_module(cr, module, if_installed) + + +def _force_install_module(cr, module, if_installed=None): + # Low level implementation + # Needs the module to exist in the database + _assert_modules_exists(cr, module) subquery = "" subparams = () if if_installed: @@ -582,7 +593,7 @@ def force_install_module(cr, module, if_installed=None): ) for (mod,) in cr.fetchall(): _logger.debug("auto install module %r due to module %r being force installed", mod, module) - force_install_module(cr, mod) + _force_install_module(cr, mod) # TODO handle module exclusions @@ -622,7 +633,7 @@ def new_module_dep(cr, module, new_dep): if mod_state in INSTALLED_MODULE_STATES: # Module was installed, need to install all its deps, recursively, # to make sure the new dep is installed - force_install_module(cr, module) + _force_install_module(cr, module) def remove_module_deps(cr, module, old_deps): @@ -726,7 +737,7 @@ def trigger_auto_install(cr, module): cr.execute(query, [module, INSTALLED_MODULE_STATES]) if cr.rowcount: - force_install_module(cr, module) + _force_install_module(cr, module) return True return False @@ -882,6 +893,7 @@ def _trigger_auto_discovery(cr): # Use accumulated values for the auto_install and force_upgrade modules. force_installs = ENVIRON["__modules_auto_discovery_force_installs"] + _assert_modules_exists(cr, *force_installs) cr.execute( """ @@ -918,7 +930,7 @@ def _trigger_auto_discovery(cr): module_auto_install(cr, module, auto_install) if module in force_installs: - force_install_module(cr, module) + _force_install_module(cr, module) for module, (init, version) in ENVIRON["__modules_auto_discovery_force_upgrades"].items(): _force_upgrade_of_fresh_module(cr, module, init, version)