Skip to content

Commit 6591347

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 (see related odoo/odoo#43306) instead of implicit access. This can lead to access errors in `custom_module_field_as_manual`, particularly in the test crawler, 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
1 parent f1f3ca2 commit 6591347

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/util/orm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,28 @@ 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 (
435+
name, model_id, active, perm_read, perm_write, perm_create, perm_unlink
436+
)
437+
SELECT 'tmp_access', ir_model.id, true, true, true, true, true
438+
FROM ir_model
439+
LEFT JOIN ir_model_access ON ir_model_access.model_id = ir_model.id
440+
WHERE ir_model.model IN %s
441+
AND ir_model.transient
442+
AND ir_model_access.id IS NULL
443+
RETURNING id
444+
""",
445+
[custom_models],
446+
)
447+
temp_ir_model_access_ids = [r[0] for r in env.cr.fetchall()]
448+
427449
# 2. Convert fields which are not in the registry to `manual` fields
428450
# and list the fields that were converted, to restore them back afterwards.
429451
# Also temporarily disable rules (ir.rule) that come from custom modules.
@@ -596,6 +618,8 @@ def patch_display_name():
596618
)
597619
if disabled_ir_rule_ids:
598620
env.cr.execute("UPDATE ir_rule SET active = 't' WHERE id IN %s", (tuple(disabled_ir_rule_ids),))
621+
if temp_ir_model_access_ids:
622+
env.cr.execute("DELETE FROM ir_model_access WHERE id IN %s", [tuple(temp_ir_model_access_ids)])
599623
for field_id, selection in updated_selection_fields:
600624
env.cr.execute("UPDATE ir_model_fields SET selection = %s WHERE id = %s", (selection, field_id))
601625
for field_id, on_delete in updated_many2one_fields:

0 commit comments

Comments
 (0)