|
43 | 43 | from openerp.addons.web.controllers.main import module_topological_sort as topological_sort |
44 | 44 |
|
45 | 45 | from .const import ENVIRON, NEARLYWARN |
46 | | -from .exceptions import MigrationError, SleepyDeveloperError |
| 46 | +from .exceptions import MigrationError, SleepyDeveloperError, UnknownModuleError |
47 | 47 | from .fields import remove_field |
48 | 48 | from .helpers import _validate_model, table_of_model |
49 | 49 | 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 |
518 | 518 | already installed |
519 | 519 | :return str: the *new* state of the module |
520 | 520 | """ |
| 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) |
521 | 535 | subquery = "" |
522 | 536 | params = [module] |
523 | 537 | 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 | + ) |
524 | 546 | subquery = """AND EXISTS(SELECT 1 FROM ir_module_module |
525 | 547 | WHERE name IN %s |
526 | 548 | AND state IN %s)""" |
@@ -642,7 +664,7 @@ def _assert_modules_exists(cr, *modules): |
642 | 664 | existing_modules = {m[0] for m in cr.fetchall()} |
643 | 665 | unexisting_modules = set(modules) - existing_modules |
644 | 666 | if unexisting_modules: |
645 | | - raise AssertionError("Unexisting modules: {}".format(", ".join(unexisting_modules))) |
| 667 | + raise UnknownModuleError(*sorted(unexisting_modules)) |
646 | 668 |
|
647 | 669 |
|
648 | 670 | def new_module_dep(cr, module, new_dep): |
@@ -973,7 +995,7 @@ def _trigger_auto_discovery(cr): |
973 | 995 | module_auto_install(cr, module, auto_install) |
974 | 996 |
|
975 | 997 | if module in force_installs: |
976 | | - force_install_module(cr, module) |
| 998 | + _force_install_module(cr, module) |
977 | 999 |
|
978 | 1000 | for module, (init, version) in ENVIRON["__modules_auto_discovery_force_upgrades"].items(): |
979 | 1001 | _force_upgrade_of_fresh_module(cr, module, init, version) |
|
0 commit comments