Skip to content

Commit

Permalink
[IMP] util/modules: force install of new modules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jjmaksoud committed Sep 24, 2024
1 parent 3c2488e commit bce810b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/util/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -486,8 +486,20 @@ 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
"""
version = _caller_version()
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)
return None
return _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:
Expand Down Expand Up @@ -582,7 +594,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

Expand Down Expand Up @@ -622,7 +634,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):
Expand Down Expand Up @@ -726,7 +738,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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bce810b

Please sign in to comment.