Skip to content

Commit bce810b

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 3c2488e commit bce810b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/util/modules.py

+18-6
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,20 @@ 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+
version = _caller_version()
491+
if version_gte("saas~14.5"):
492+
# We must delay until the modules actually exists. They are added by the auto discovery process.
493+
if not if_installed or modules_installed(cr, *if_installed):
494+
ENVIRON["__modules_auto_discovery_force_installs"].add(module)
495+
return None
496+
return _force_install_module(cr, module, if_installed)
497+
498+
499+
def _force_install_module(cr, module, if_installed=None):
500+
# Low level implementation
501+
# Needs the module to exist in the database
502+
_assert_modules_exists(cr, module)
491503
subquery = ""
492504
subparams = ()
493505
if if_installed:
@@ -582,7 +594,7 @@ def force_install_module(cr, module, if_installed=None):
582594
)
583595
for (mod,) in cr.fetchall():
584596
_logger.debug("auto install module %r due to module %r being force installed", mod, module)
585-
force_install_module(cr, mod)
597+
_force_install_module(cr, mod)
586598

587599
# TODO handle module exclusions
588600

@@ -622,7 +634,7 @@ def new_module_dep(cr, module, new_dep):
622634
if mod_state in INSTALLED_MODULE_STATES:
623635
# Module was installed, need to install all its deps, recursively,
624636
# to make sure the new dep is installed
625-
force_install_module(cr, module)
637+
_force_install_module(cr, module)
626638

627639

628640
def remove_module_deps(cr, module, old_deps):
@@ -726,7 +738,7 @@ def trigger_auto_install(cr, module):
726738

727739
cr.execute(query, [module, INSTALLED_MODULE_STATES])
728740
if cr.rowcount:
729-
force_install_module(cr, module)
741+
_force_install_module(cr, module)
730742
return True
731743
return False
732744

@@ -918,7 +930,7 @@ def _trigger_auto_discovery(cr):
918930
module_auto_install(cr, module, auto_install)
919931

920932
if module in force_installs:
921-
force_install_module(cr, module)
933+
_force_install_module(cr, module)
922934

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

0 commit comments

Comments
 (0)