[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
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user