From 7a82891c59c37359e0bebb6a84fa04b2a4e3fe9a Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Wed, 7 Oct 2020 10:50:21 +0000 Subject: [PATCH] [FIX] base_import_module: avoid accessing deleted columns Commit 59eee6ba5fed0ba74221f44a296ec6efedbc2527 introduced a cleanup mechanism for external data modules being uninstalled from a database, this meant deleting the ir.module.module entry created when first installing the aforementioned external module. However, the above patch has one small oversight: the access of the `imported` field introduced by the `base_import_module` module is done after the `super().module_uninstall()` call which, in the case of the uninstall of the `base_import_module` module, will delete the `imported` column and the following call to filtered will fail because the column has already been deleted and the registry hasn't been reloaded yet. The solution to this, as explained in the code comment, is to simply compute the `modules_to_delete` before the call to `module_uninstall()`. closes odoo/odoo#59418 X-original-commit: c0226087b82ffda3971bb953d8d00b8c5e67642c Signed-off-by: Raphael Collet (rco) Signed-off-by: Adrian Torres (adt) --- addons/base_import_module/models/ir_module.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index 9e2116507a6..f245ead654c 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -151,8 +151,11 @@ class IrModule(models.Model): # one. The rationale behind this is that an imported module *cannot* be # reinstalled anyway, as it requires the data files. Any attempt to # install it again will simply fail without trace. - res = super().module_uninstall() + # /!\ modules_to_delete must be calculated before calling super().module_uninstall(), + # because when uninstalling `base_import_module` the `imported` column will no longer be + # in the database but we'll still have an old registry that runs this code. modules_to_delete = self.filtered('imported') + res = super().module_uninstall() if modules_to_delete: _logger.info("deleting imported modules upon uninstallation: %s", ", ".join(modules_to_delete.mapped('name')))