Skip to content

Commit 39e1b8b

Browse files
committed
[FIX] util/modules: trigger autodiscovery outside major upgrade
Outside a major upgrade `base` is already fully loaded. New modules are yet not known for the ORM. We thus need to trigger the discovery. During a major upgrade we also want to block force installing modules outside `base` pre/post. closes #333 Signed-off-by: Christophe Simonis (chs) <chs@odoo.com> Co-authored-by: maji@odoo.com Co-authored-by: chs@odoo.com
1 parent 90f75e6 commit 39e1b8b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/base/0.0.0/post-01-modules-auto-discovery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
def migrate(cr, version):
77
if util.version_gte("saas~14.5"):
88
_trigger_auto_discovery(cr)
9+
util.ENVIRON["AUTO_DISCOVERY_UPGRADE"] = True

src/util/modules.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
INSTALLED_MODULE_STATES = ("installed", "to install", "to upgrade")
5656
_logger = logging.getLogger(__name__)
5757

58+
ENVIRON.setdefault("AUTO_DISCOVERY_RAN", False)
59+
5860
if version_gte("15.0"):
5961
AUTO_INSTALL = os.getenv("UPG_AUTOINSTALL")
6062
_NO_AUTOINSTALL = os.getenv("UPG_NO_AUTOINSTALL")
@@ -553,6 +555,14 @@ def force_install_module(cr, module, if_installed=None, reason="it has been expl
553555
if if_installed:
554556
_assert_modules_exists(cr, *if_installed)
555557
if not if_installed or modules_installed(cr, *if_installed):
558+
cr.execute("SELECT 1 FROM ir_module_module WHERE name = 'base' AND state != 'to upgrade'")
559+
if cr.rowcount:
560+
if not ENVIRON.get("AUTO_DISCOVERY_RAN"):
561+
# run the autodiscovery once to allow to force install _new_ modules
562+
_trigger_auto_discovery(cr)
563+
elif ENVIRON.get("AUTO_DISCOVERY_UPGRADE"):
564+
raise MigrationError("`force_install_module` can only be called from pre/post of `base`")
565+
return _force_install_module(cr, module, reason="{} (done outside of a major upgrade)".format(reason))
556566
ENVIRON["__modules_auto_discovery_force_installs"].add(module)
557567
return None
558568
else:
@@ -995,6 +1005,8 @@ def _trigger_auto_discovery(cr):
9951005
# Called by `base/0.0.0/post-modules-auto-discovery.py` script.
9961006
# Use accumulated values for the auto_install and force_upgrade modules.
9971007

1008+
ENVIRON["AUTO_DISCOVERY_RAN"] = True
1009+
9981010
force_installs = ENVIRON["__modules_auto_discovery_force_installs"]
9991011

10001012
cr.execute(

0 commit comments

Comments
 (0)