From c643be7679921026a87ff307d57b38c174ec439e Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Thu, 30 Jan 2020 15:32:13 +0000 Subject: [PATCH] [IMP] base: ensure correct inheritance chain in registry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When removing a custom model, it remained listed in the base classes (normally `base` and also possibly a list of mixins; e.g. `mail.thread` or `mail.activity.mixin`) list of inheriting classes, possibly causing a crash when trying to reload the registry. This commit ensures that any custom model is removed from its parent class `_inherit_children` set; it will be re-added automatically during the call to `_build_model` if the custom model still exists. Co-Authored-By: Raphaƫl Collet --- odoo/addons/base/models/ir_model.py | 2 +- odoo/modules/registry.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 7d7a93d7f87..76477936439 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -308,7 +308,7 @@ class IrModel(models.Model): # clean up registry first custom_models = [name for name, model_class in self.pool.items() if model_class._custom] for name in custom_models: - del self.pool.models[name] + del self.pool[name] # add manual models cr = self.env.cr cr.execute('SELECT * FROM ir_model WHERE state=%s', ['manual']) diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index dc03d0b24d3..ddb1631ec51 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -183,6 +183,13 @@ class Registry(Mapping): """ Add or replace a model in the registry.""" self.models[model_name] = model + def __delitem__(self, model_name): + """ Remove a (custom) model from the registry. """ + del self.models[model_name] + # the custom model can inherit from mixins ('mail.thread', ...) + for Model in self.models.values(): + Model._inherit_children.discard(model_name) + def descendants(self, model_names, *kinds): """ Return the models corresponding to ``model_names`` and all those that inherit/inherits from them.