Skip to content

Commit 23a624a

Browse files
committed
[ADD] module_auto_update: allow updates in a minimal environment
1 parent c1177ac commit 23a624a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

module_auto_update/models/module.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import json
66
import logging
77
import os
8+
from collections import namedtuple
89

9-
from odoo import _, api, exceptions, models, tools
10+
from odoo import SUPERUSER_ID, _, api, exceptions, models, tools
1011
from odoo.modules.module import get_module_path
12+
from odoo.modules.registry import Registry
1113

1214
from ..addon_hash import addon_hash
1315

@@ -196,3 +198,23 @@ def upgrade_changed_checksum(self, overwrite_existing_translations=False):
196198
"sticky": False,
197199
},
198200
}
201+
202+
def upgrade_changed_checksum_shell(self, overwrite_existing_translations=False):
203+
"""Call upgrade_changed_checksum, but in a minimal environment that
204+
doesn't fail when base models like res.users or ir.model have been changed.
205+
206+
This function is designed to be called in a shell that ends immediately
207+
afterwards, as it destroys the current session.
208+
"""
209+
fake_module = namedtuple("fake_module", ["name"])
210+
self.env.cr.close()
211+
with self.env.registry.cursor() as _cr:
212+
Registry.delete_all()
213+
minimal_registry = object.__new__(Registry)
214+
minimal_registry.init(_cr.dbname)
215+
minimal_registry.load(_cr, fake_module("base"))
216+
minimal_registry.load(_cr, fake_module("module_auto_update"))
217+
_cr.transaction = api.Transaction(minimal_registry)
218+
minimal_registry.setup_models(_cr)
219+
minimal_env = api.Environment(_cr, SUPERUSER_ID, {})
220+
minimal_env["ir.module.module"].upgrade_changed_checksum()

module_auto_update/readme/USAGE.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ in an Odoo shell session:
1919

2020
.. code-block:: python
2121
22-
env['ir.module.module'].upgrade_changed_checksum()
22+
env['ir.module.module'].upgrade_changed_checksum_shell()

0 commit comments

Comments
 (0)