Skip to content

Commit 32e8b77

Browse files
committed
[FIX] util.remove_inherit_from_model: ignore mixins m2m
In mixins, the one2many are actually targeted by the res_model/res_id couple (i.e. `mail_message` on `mail.thread`). We should then ignore the indirect references without a `res_id` column. Stored m2m should be handled by the caller. We needs to actually remove the m2m table (should be unique per model) and as we don't know the table name (info not reflected in the database), we can't delete it ourself. This issue has been found during the `17.0` upgrade of `base_automation`, which removes the `ir.actions.server` inherit[^1]. As the `ir.actions.server` contains a m2m on `ir.model.fields` (`webhook_field_ids`), without the `res_id` filter, all the the `base.automation` fields entries where removed (including the custom fields ones). [^1]: odoo/odoo#114352 closes #86 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 2fa15b8 commit 32e8b77

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/util/models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,10 @@ def remove_inherit_from_model(cr, model, inherit, keep=(), skip_inherit=()):
512512
[tuple(inherit_models), list(keep)],
513513
)
514514
for field, ftype, relation, store in cr.fetchall():
515-
if ftype.endswith("2many") and store:
516-
# for mixin, x2many are filtered by their model.
517-
# for "classic" inheritance, the caller is responsible to drop the underlying m2m table
518-
# (or keeping the field)
515+
if ftype == "one2many" and store:
516+
# for mixin, one2many are filtered by their model and res_id.
519517
table = table_of_model(cr, relation)
520-
irs = [ir for ir in indirect_references(cr) if ir.table == table]
518+
irs = [ir for ir in indirect_references(cr) if ir.table == table and ir.res_id is not None]
521519
for ir in irs:
522520
query = 'DELETE FROM "{}" WHERE ({})'.format(ir.table, ir.model_filter())
523521
cr.execute(query, [model]) # cannot be executed in parallel. See git blame.

0 commit comments

Comments
 (0)