From 7f443e85423c03ed6d7668cb0d767e8ff6ea3ecd Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 22 Sep 2022 12:40:08 +0000 Subject: [PATCH] [IMP] base: Prevent button_immediate_install on non loaded registries If called in cascade, this could lead to a situation in which a same thread is trying to create recursively several registries when loading the sames modules, which obviously cannot work in any way. Use button_install instead, that will simply update the module state while waiting to be installed in a proper way, instead of forcing a registry creation that will mess the whole process. X-original-commit: 6b52844a8dc78788cbd948c7e2f90156ee8b89d7 Part-of: odoo/odoo#101086 --- addons/base_setup/tests/test_res_config.py | 4 ++-- odoo/addons/base/models/ir_module.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/base_setup/tests/test_res_config.py b/addons/base_setup/tests/test_res_config.py index ab24395a9de..68e1ca126fa 100644 --- a/addons/base_setup/tests/test_res_config.py +++ b/addons/base_setup/tests/test_res_config.py @@ -79,7 +79,7 @@ class TestResConfig(TransactionCase): self.assertTrue(module.state != 'uninstalled', "All set modules should already be installed.") # if we try to install something, raise; so nothing should be installed - with patch('odoo.addons.base.models.ir_module.Module._button_immediate_function', new=just_raise): + with patch('odoo.addons.base.models.ir_module.Module.button_immediate_install', new=just_raise): self.config.execute() def test_install(self): @@ -91,6 +91,6 @@ class TestResConfig(TransactionCase): module_to_install = next(m for m in config_fields['module'] if m.state == 'uninstalled') self.config[f'module_{module_to_install.name}'] = True - with patch('odoo.addons.base.models.ir_module.Module._button_immediate_function', new=just_raise): + with patch('odoo.addons.base.models.ir_module.Module.button_immediate_install', new=just_raise): with self.assertRaisesRegex(Exception, "We should not be here."): self.config.execute() diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py index a8ce7c0947a..a9bf07ce405 100644 --- a/odoo/addons/base/models/ir_module.py +++ b/odoo/addons/base/models/ir_module.py @@ -585,6 +585,9 @@ class Module(models.Model): } def _button_immediate_function(self, function): + if not self.env.registry.ready or self.env.registry._init: + raise UserError(_('The method _button_immediate_install cannot be called on init or non loaded registries. Please use button_install instead.')) + if getattr(threading.current_thread(), 'testing', False): raise RuntimeError( "Module operations inside tests are not transactional and thus forbidden.\n"