From 4287a701103e557dc577005dfb8867d2f0970e39 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 21 Apr 2017 11:31:12 +0200 Subject: [PATCH] [FIX] models: remove `ir.model.fields` that no longer exist in registry This fixes the following issue. Assume a custom field F is created on `res.partner`. This field will appear on `res.users` as an inherited field, and will be reflected in `ir.model.fields` as a 'base' field. When F is removed from the parent model, it no longer appears on the child model in registry, but remains in `ir.model.fields`. The patch allows the proper removal of the no-longer-inherited field from `ir.model.fields`. --- odoo/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/odoo/models.py b/odoo/models.py index 4c8dc9c6630..e908f3609f5 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -368,6 +368,15 @@ class BaseModel(object): field_id = cr.fetchone()[0] self._context['todo'].append((20, Fields.browse(field_id).modified, [names])) + if not self.pool._init: + # remove ir.model.fields that are not in self._fields + fields = Fields.browse([col['id'] + for name, col in cols.iteritems() + if name not in self._fields]) + # add key '_force_unlink' in context to (1) force the removal of the + # fields and (2) not reload the registry + fields.with_context(_force_unlink=True).unlink() + self.invalidate_cache() @api.model