From 25a6f79e4aa5fb90b7fa7213a2462b1b8244d80d Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Fri, 4 Dec 2020 12:00:38 +0000 Subject: [PATCH] [FIX] base: key error during uninstall of unavailable module In case a user has installed a module where the code becomes unavailable or during migration a module was removed and needs to be removed after migration it is impossible to uninstall the module from a database still holding the fields or the models. In order to disable prefetch based on information from the database it is needed that the module and models of the unavailable module are initialized with related fields and models. closes odoo/odoo#62895 X-original-commit: e4a1121e572d07cc720ede8c1b1116d4f1d7ae98 Signed-off-by: Raphael Collet (rco) --- odoo/addons/base/models/ir_model.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 716624110bd..ae7deeb22f6 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -2071,8 +2071,11 @@ class IrModelData(models.Model): # methods is not in cache it will be fetched, and fields that exist in the registry but not # in the database will be prefetched, this will of course fail and prevent the uninstall. for ir_field in self.env['ir.model.fields'].browse(field_ids): - field = self.pool[ir_field.model]._fields[ir_field.name] - field.prefetch = False + model = self.pool.get(ir_field.model) + if model is not None: + field = model._fields.get(ir_field.name) + if field is not None: + field.prefetch = False # to collect external ids of records that cannot be deleted undeletable_ids = []