From 962412c309528785bcbaeadfe69eeee740932f85 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 2 Apr 2020 13:59:21 +0000 Subject: [PATCH] [FIX] test_website: upgrading inside a test is really not a good idea Because: (1) the upgrade starts by committing the current cursor; then (2) the upgrade instanciates a new registry to use for the database; and (3) the test cleanup involves setting up the old registry, which creates a new environment referring to the new registry! The points (2) and (3) makes the field setup crash when it relies on data stored on the registry itself: the field in the old registry tries to set up with data stored on the old registry. closes odoo/odoo#48920 X-original-commit: f5e5aba9e203b42b661cc3b503fd37051ec20f93 Signed-off-by: Raphael Collet (rco) --- .../tests/test_views_during_module_operation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/test_website/tests/test_views_during_module_operation.py b/addons/test_website/tests/test_views_during_module_operation.py index 530284e2645..e960291bf22 100644 --- a/addons/test_website/tests/test_views_during_module_operation.py +++ b/addons/test_website/tests/test_views_during_module_operation.py @@ -62,6 +62,12 @@ class TestViewsDuringModuleOperation(TransactionCase): self.assertTrue(self.env.ref(update_module_view_to_be_t_called.key)) self.assertTrue(self.env.ref(update_module_base_view.key)) + # the upgrade of the module below instanciates a NEW registry, so we + # have to restore the old one in order to perform the cleanups + @self.addCleanup + def cleanup(): + self.registry.registries[self.registry.db_name] = self.registry + # Update the module test_website_module = self.env['ir.module.module'].search([('name', '=', 'test_website')]) test_website_module.button_immediate_upgrade()