Skip to content

Commit cb77ad0

Browse files
committed
[FIX] util.force_install_module
Auto-delay to auto-discovery for new modules. Part-of: #315 Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
1 parent 5fce1ec commit cb77ad0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/util/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ class SleepyDeveloperError(ValueError):
99
pass
1010

1111

12+
class UnknownModuleError(AssertionError):
13+
pass
14+
15+
1216
# Compat
1317
MigrationError = UpgradeError

src/util/modules.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from openerp.addons.web.controllers.main import module_topological_sort as topological_sort
4444

4545
from .const import ENVIRON, NEARLYWARN
46-
from .exceptions import MigrationError, SleepyDeveloperError
46+
from .exceptions import MigrationError, SleepyDeveloperError, UnknownModuleError
4747
from .fields import remove_field
4848
from .helpers import _validate_model, table_of_model
4949
from .misc import on_CI, str2bool, version_gte
@@ -518,9 +518,31 @@ def force_install_module(cr, module, if_installed=None, reason="it has been expl
518518
already installed
519519
:return str: the *new* state of the module
520520
"""
521+
try:
522+
return _force_install_module(cr, module, if_installed, reason)
523+
except UnknownModuleError:
524+
if version_gte("saas~14.5"):
525+
# We must delay until the modules actually exists. They are added by the auto discovery process.
526+
ENVIRON["__modules_auto_discovery_force_installs"].add(module)
527+
return None
528+
else:
529+
raise
530+
531+
532+
def _force_install_module(cr, module, if_installed=None, reason="it has been explicitly asked for"):
533+
"""Strict implementation of force_install: raise errors for missing modules."""
534+
_assert_modules_exists(cr, module)
521535
subquery = ""
522536
params = [module]
523537
if if_installed:
538+
try:
539+
_assert_modules_exists(cr, *if_installed)
540+
except UnknownModuleError as e:
541+
# Warn about unknown modules (can help track typos in the call).
542+
# we don't care about missing modules, as by definition, they are not installed.
543+
_logger.log(
544+
NEARLYWARN, "Unknown 'if_installed' modules: %s; consider them as uninstalled.", ", ".join(e.args)
545+
)
524546
subquery = """AND EXISTS(SELECT 1 FROM ir_module_module
525547
WHERE name IN %s
526548
AND state IN %s)"""
@@ -642,7 +664,7 @@ def _assert_modules_exists(cr, *modules):
642664
existing_modules = {m[0] for m in cr.fetchall()}
643665
unexisting_modules = set(modules) - existing_modules
644666
if unexisting_modules:
645-
raise AssertionError("Unexisting modules: {}".format(", ".join(unexisting_modules)))
667+
raise UnknownModuleError(*sorted(unexisting_modules))
646668

647669

648670
def new_module_dep(cr, module, new_dep):
@@ -973,7 +995,7 @@ def _trigger_auto_discovery(cr):
973995
module_auto_install(cr, module, auto_install)
974996

975997
if module in force_installs:
976-
force_install_module(cr, module)
998+
_force_install_module(cr, module)
977999

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

0 commit comments

Comments
 (0)