[FIX] core: update of custom models in registry

When removing custom models from the registry, one also has to remove
indirect references to those model.  One such reference is the name of
the custom model in its parent models' `_inherit_children`.

Not removing that reference causes a crash when one of the parent models
is extended: the parent model will make its children models recompute
some of their attributes (see method `_build_model_attributes`).

closes odoo/odoo#62008

X-original-commit: 07404bf5e93878b26468e2944c69885bbc688e57
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Raphael Collet
2020-11-19 11:39:38 +00:00
parent 5e6bf8579b
commit 747ce6adcc
+7 -3
View File
@@ -411,9 +411,13 @@ class IrModel(models.Model):
def _add_manual_models(self):
""" Add extra models to the registry. """
# 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[name]
for name, Model in list(self.pool.items()):
if Model._custom:
del self.pool.models[name]
# remove the model's name from its parents' _inherit_children
for Parent in Model.__bases__:
if hasattr(Parent, 'pool'):
Parent._inherit_children.discard(name)
# add manual models
cr = self.env.cr
cr.execute('SELECT * FROM ir_model WHERE state=%s', ['manual'])