[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
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user