Skip to content

Commit badd3d8

Browse files
committed
[FIX] modules: defer new dependency installs
When updating module dependencies from graph with auto discovery, all dependency diffs should be saved before attempting the installation of the modules that are new dependencies for installed modules, or force installed modules. When a module is force installed from pre-scripts using force_install_module, always defer the installation to post-base in _trigger_auto_discovery until all deps are updated. This is to avoid auto installing unwanted modules based on their old dependencies. closes #331 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 5082db9 commit badd3d8

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

src/util/modules.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -549,20 +549,25 @@ def force_install_module(cr, module, if_installed=None, reason="it has been expl
549549
already installed
550550
:return str: the *new* state of the module
551551
"""
552-
try:
553-
return _force_install_module(cr, module, if_installed, reason)
554-
except UnknownModuleError:
555-
if version_gte("saas~14.5"):
556-
# We must delay until the modules actually exists. They are added by the auto discovery process.
552+
if version_gte("saas~14.5"):
553+
if if_installed:
554+
_assert_modules_exists(cr, *if_installed)
555+
if not if_installed or modules_installed(cr, *if_installed):
557556
ENVIRON["__modules_auto_discovery_force_installs"].add(module)
558-
return None
559-
else:
560-
raise
557+
return None
558+
else:
559+
return _force_install_module(cr, module, if_installed, reason)
561560

562561

563562
def _force_install_module(cr, module, if_installed=None, reason="it has been explicitly asked for"):
564563
"""Strict implementation of force_install: raise errors for missing modules."""
565564
_assert_modules_exists(cr, module)
565+
566+
cr.execute("SELECT state FROM ir_module_module WHERE name = %s", [module])
567+
mod_state = cr.fetchone()[0]
568+
if mod_state in INSTALLED_MODULE_STATES:
569+
return mod_state
570+
566571
subquery = ""
567572
params = [module]
568573
if if_installed:
@@ -675,7 +680,7 @@ def _force_install_module(cr, module, if_installed=None, reason="it has been exp
675680
[toinstall, list(INSTALLED_MODULE_STATES)],
676681
)
677682
for (mod,) in cr.fetchall():
678-
force_install_module(
683+
_force_install_module(
679684
cr,
680685
mod,
681686
reason=(
@@ -716,13 +721,14 @@ def new_module_dep(cr, module, new_dep):
716721
[new_dep, module, new_dep],
717722
)
718723

719-
# Update new_dep state depending on module state
720-
cr.execute("SELECT state FROM ir_module_module WHERE name = %s", [module])
721-
mod_state = (cr.fetchone() or ["n/a"])[0]
722-
if mod_state in INSTALLED_MODULE_STATES:
723-
# Module was installed, need to install all its deps, recursively,
724-
# to make sure the new dep is installed
725-
force_install_module(cr, new_dep, reason="it's a new dependency of {!r}".format(module))
724+
if not version_gte("saas~14.5"):
725+
# Update new_dep state depending on module state
726+
cr.execute("SELECT state FROM ir_module_module WHERE name = %s", [module])
727+
mod_state = (cr.fetchone() or ["n/a"])[0]
728+
if mod_state in INSTALLED_MODULE_STATES:
729+
# Module was installed, need to install all its deps, recursively,
730+
# to make sure the new dep is installed
731+
_force_install_module(cr, new_dep, reason="it's a new dependency of {!r}".format(module))
726732

727733

728734
def remove_module_deps(cr, module, old_deps):
@@ -1025,8 +1031,25 @@ def _trigger_auto_discovery(cr):
10251031
_set_module_countries(cr, module, countries)
10261032
module_auto_install(cr, module, auto_install)
10271033

1028-
if module in force_installs:
1029-
_force_install_module(cr, module)
1034+
cr.execute(
1035+
"""
1036+
SELECT d.name, STRING_AGG(m.name, ', ' ORDER BY m.name)
1037+
FROM ir_module_module_dependency d
1038+
JOIN ir_module_module m
1039+
ON d.module_id = m.id
1040+
JOIN ir_module_module dm
1041+
ON dm.name = d.name
1042+
WHERE m.state IN %(installed_state)s
1043+
AND dm.state NOT IN %(installed_state)s
1044+
GROUP BY d.name
1045+
""",
1046+
{"installed_state": INSTALLED_MODULE_STATES},
1047+
)
1048+
for new_dep, modules in cr.fetchall():
1049+
_force_install_module(cr, new_dep, reason="it's a new dependency of {}".format(modules))
1050+
1051+
for module in force_installs:
1052+
_force_install_module(cr, module)
10301053

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

0 commit comments

Comments
 (0)