Skip to content

Commit d536368

Browse files
committed
[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.
1 parent 79f3d71 commit d536368

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/util/modules.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def _up(table, old, new):
476476
cr.execute("DELETE FROM ir_module_module_dependency WHERE name=%s", [old])
477477
cr.execute("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s", [mod_ids[old]])
478478
if state in INSTALLED_MODULE_STATES:
479-
force_install_module(cr, into)
479+
_force_install_module(cr, into)
480480

481481

482482
def force_install_module(cr, module, if_installed=None):
@@ -486,8 +486,19 @@ def force_install_module(cr, module, if_installed=None):
486486
:param str module: name of the module to install
487487
:param list(str) or None if_installed: only force the install when these modules are
488488
already installed
489-
:return str: the *original* state of the module
490489
"""
490+
if version_gte("saas~14.5"):
491+
# We must delay until the modules actually exists. They are added by the auto discovery process.
492+
if not if_installed or modules_installed(cr, *if_installed):
493+
ENVIRON["__modules_auto_discovery_force_installs"].add(module)
494+
else:
495+
_force_install_module(cr, module, if_installed)
496+
497+
498+
def _force_install_module(cr, module, if_installed=None):
499+
# Low level implementation
500+
# Needs the module to exist in the database
501+
_assert_modules_exists(cr, module, *if_installed or ())
491502
subquery = ""
492503
subparams = ()
493504
if if_installed:
@@ -582,7 +593,7 @@ def force_install_module(cr, module, if_installed=None):
582593
)
583594
for (mod,) in cr.fetchall():
584595
_logger.debug("auto install module %r due to module %r being force installed", mod, module)
585-
force_install_module(cr, mod)
596+
_force_install_module(cr, mod)
586597

587598
# TODO handle module exclusions
588599

@@ -622,7 +633,7 @@ def new_module_dep(cr, module, new_dep):
622633
if mod_state in INSTALLED_MODULE_STATES:
623634
# Module was installed, need to install all its deps, recursively,
624635
# to make sure the new dep is installed
625-
force_install_module(cr, module)
636+
_force_install_module(cr, module)
626637

627638

628639
def remove_module_deps(cr, module, old_deps):
@@ -726,7 +737,7 @@ def trigger_auto_install(cr, module):
726737

727738
cr.execute(query, [module, INSTALLED_MODULE_STATES])
728739
if cr.rowcount:
729-
force_install_module(cr, module)
740+
_force_install_module(cr, module)
730741
return True
731742
return False
732743

@@ -852,6 +863,7 @@ def _force_upgrade_of_fresh_module(cr, module, init, version):
852863
# Low level implementation
853864
# Force module state to be in `to upgrade`.
854865
# Needed for migration script execution. See http://git.io/vnF7f
866+
_assert_modules_exists(cr, module)
855867
cr.execute(
856868
"""
857869
UPDATE ir_module_module
@@ -917,8 +929,11 @@ def _trigger_auto_discovery(cr):
917929
_set_module_countries(cr, module, countries)
918930
module_auto_install(cr, module, auto_install)
919931

920-
if module in force_installs:
921-
force_install_module(cr, module)
932+
if force_installs:
933+
_assert_modules_exists(cr, *force_installs)
934+
935+
for module in force_installs:
936+
_force_install_module(cr, module)
922937

923938
for module, (init, version) in ENVIRON["__modules_auto_discovery_force_upgrades"].items():
924939
_force_upgrade_of_fresh_module(cr, module, init, version)

0 commit comments

Comments
 (0)