Skip to content

Commit

Permalink
[FIX] base: ensure existing ir.model.constraint xmlids are loaded
Browse files Browse the repository at this point in the history
When we load a module and the SQL constraints exist both in the table
and in `ir_model_constraint` we need to ensure the xmlid is loaded.
Otherwise the record in `ir_model_constraint` is removed.

Since 4c99683 we skip returning
existing non-updated constraint records in `_reflect_constraint`. This
leads to them being removed by the ORM. At the end of the load the ORM
sees the record in `ir_model_data` but not in the xmlid pool, thus it
removes it.

closes odoo#162105

X-original-commit: b5670c7
Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
  • Loading branch information
aj-fuentes committed Apr 16, 2024
1 parent 992532e commit b278241
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion odoo/addons/base/models/ir_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1873,9 +1873,11 @@ def cons_text(txt):
conname = '%s_%s' % (model._table, key)
module = constraint_module.get(key)
record = self._reflect_constraint(model, conname, 'u', cons_text(definition), module, message)
xml_id = '%s.constraint_%s' % (module, conname)
if record:
xml_id = '%s.constraint_%s' % (module, conname)
data_list.append(dict(xml_id=xml_id, record=record))
else:
self.env['ir.model.data']._load_xmlid(xml_id)
if data_list:
self.env['ir.model.data']._update_xmlids(data_list)

Expand Down
2 changes: 1 addition & 1 deletion odoo/addons/base/tests/test_ir_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def test_related_field(self):

# create a non-computed field, and assert how many queries it takes
model_id = self.env['ir.model']._get_id('res.partner')
query_count = 44
query_count = 48
with self.assertQueryCount(query_count):
self.env.registry.clear_cache()
self.env['ir.model.fields'].create({
Expand Down

0 comments on commit b278241

Please sign in to comment.