[IMP] base: ensure correct inheritance chain in registry

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 <rco@odoo.com>
This commit is contained in:
Damien Bouvy
2020-01-31 12:06:46 +00:00
co-authored by Raphaël Collet
parent eaccecd6cc
commit c643be7679
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -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'])
+7
View File
@@ -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.