Skip to content

Commit 1f58187

Browse files
committed
[FIX] util.force_upgrade_of_fresh_module
The purpose of this function is to cheat about upgrade status of a "to install" module. Before saas~18.2: As the `MigrationManager` only handle the "to upgrade" modules, we need a way to tell the ORM that, even it is in "to upgrade", the module should be loaded in "init" mode (this control the behavior of the `forcecreate` flag of the records). That was done using the global `config["init"]` dict. Since saas~18.2: Now, this is done the other way around. It's the `MigrationManager` that is aware of "to install" modules that upgrade scripts should be executed. This is done via the `_force_upgrade_scripts` set on the registry. The module state stay in "to install". In either case, we should set the module version to the version of the calling script. Note: this only affect the `init=True` calling mode (default). When called with `init=False`, we always lie about the module state and don't tell the ORM about it. Oversight of #176 closes #291 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent b977faa commit 1f58187

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/util/modules.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -897,26 +897,26 @@ def _force_upgrade_of_fresh_module(cr, module, init, version):
897897
# Low level implementation
898898
# Force module state to be in `to upgrade`.
899899
# Needed for migration script execution. See http://git.io/vnF7f
900-
if version_gte("saas~18.2") and init:
901-
env_ = env(cr)
902-
env_.registry._force_upgrade_scripts.add(module)
903-
return
904-
900+
state = "to install" if init and version_gte("saas~18.2") else "to upgrade"
905901
cr.execute(
906902
"""
907903
UPDATE ir_module_module
908-
SET state='to upgrade',
904+
SET state=%s,
909905
latest_version=%s
910906
WHERE name=%s
911907
AND state='to install'
912908
RETURNING id
913909
""",
914-
[version, module],
910+
[state, version, module],
915911
)
916912
if init and cr.rowcount:
917-
# Force module in `init` mode beside its state is forced to `to upgrade`
918-
# See http://git.io/vnF7O
919-
odoo.tools.config["init"][module] = "oh yeah!"
913+
if version_gte("saas~18.2"):
914+
env_ = env(cr)
915+
env_.registry._force_upgrade_scripts.add(module)
916+
else:
917+
# Force module in `init` mode beside its state is forced to `to upgrade`
918+
# See http://git.io/vnF7O
919+
odoo.tools.config["init"][module] = "oh yeah!"
920920

921921

922922
# for compatibility

0 commit comments

Comments
 (0)