From 86ef5d1a46e80474f9cb7ca3cf9c3e1c77eedc12 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 14 Jan 2019 14:38:15 +0000 Subject: [PATCH] [FIX] ir_model: properly delete m2m whose comodel is being deleted Before this patch, if an m2m's relation field pointed to a model that was to be deleted, the deletion of the aforementioned model wouldn't trigger the m2m's deletion, which would lead to the registry crashing. With this patch, whenever an ir.model is being unlinked, a check is performed to verify that no other fields (m2m or otherwise) have this model as a comodel, and if they do, they are unlinked as well. closes odoo/odoo#30230 --- odoo/addons/base/ir/ir_model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/odoo/addons/base/ir/ir_model.py b/odoo/addons/base/ir/ir_model.py index 05b7ca53240..7f94d6649c8 100644 --- a/odoo/addons/base/ir/ir_model.py +++ b/odoo/addons/base/ir/ir_model.py @@ -180,6 +180,9 @@ class IrModel(models.Model): # prevent screwing up fields that depend on these models' fields model.field_id._prepare_update() + # delete fields whose comodel is being removed + self.env['ir.model.fields'].search([('relation', 'in', self.mapped('model'))]).unlink() + self._drop_table() res = super(IrModel, self).unlink()