Skip to content

Commit 4958d6b

Browse files
committed
[FIX] util/orm.py: fix custom_module_field_as_manual transient access
From Odoo version 14.0 transient models require access rights instead of implicit access (see related odoo/odoo#43306). This can lead to access errors in `custom_module_field_as_manual`, particularly in the upgrade TestCrawler, leading to blocked upgrades. To reproduce: - have a v13 db with a custom menu which opens a custom model's view, having a relational field (e.g. one2many) to a custom transient model, and have existing records - run the upgrade test prepare - upgrade to v14 - run the upgrade test check, the TestCrawler will fail with an AccessError To fix that, create temporary access rights for custom transient models while using the context manager. upg-1157201 closes #8 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 522c48e commit 4958d6b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/util/orm.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,27 @@ def custom_module_field_as_manual(env, rollback=True, do_flush=False):
424424
)
425425
mock_x_email_fields = [r[0] for r in env.cr.fetchall()]
426426

427+
temp_ir_model_access_ids = []
428+
if version_gte("14.0") and custom_models:
429+
# 1.2 Version 14.0 and above requires new access rights for transient models,
430+
# and the rights are yet to be added post standard upgrade for custom modules.
431+
# To avoid access errors, create some temporary access rights for these models.
432+
env.cr.execute(
433+
"""
434+
INSERT INTO ir_model_access (name, model_id, active, perm_read)
435+
SELECT 'tmp_access', ir_model.id, true, true
436+
FROM ir_model
437+
LEFT JOIN ir_model_access
438+
ON ir_model_access.model_id = ir_model.id
439+
WHERE ir_model.model IN %s
440+
AND ir_model.transient
441+
AND ir_model_access.id IS NULL
442+
RETURNING id
443+
""",
444+
[custom_models],
445+
)
446+
temp_ir_model_access_ids = [r[0] for r in env.cr.fetchall()]
447+
427448
# 2. Convert fields which are not in the registry to `manual` fields
428449
# and list the fields that were converted, to restore them back afterwards.
429450
# Also temporarily disable rules (ir.rule) that come from custom modules.
@@ -596,6 +617,8 @@ def patch_display_name():
596617
)
597618
if disabled_ir_rule_ids:
598619
env.cr.execute("UPDATE ir_rule SET active = 't' WHERE id IN %s", (tuple(disabled_ir_rule_ids),))
620+
if temp_ir_model_access_ids:
621+
env.cr.execute("DELETE FROM ir_model_access WHERE id IN %s", [tuple(temp_ir_model_access_ids)])
599622
for field_id, selection in updated_selection_fields:
600623
env.cr.execute("UPDATE ir_model_fields SET selection = %s WHERE id = %s", (selection, field_id))
601624
for field_id, on_delete in updated_many2one_fields:

0 commit comments

Comments
 (0)