Skip to content
Browse files

[FIX] base: when saving settings, only reset environment if modules w…

…ere installed/uninstalled

Execute the tests from ea574fe and 9e9ac5c,
which are in a SavepointCase.
The second test fails on a cache_miss.
Whats happens is the following:
 - the second test starts with the environment from the beginning of the
   first test. However its envs has a reference to environments that
   were created during the first test.
 - when computing the field, the ORM finds the value in a zombie
   environment, so does not recompute it
 - when trying to get the value, the value is not in cache

The issue is that going through res.config.settings's execute resets the

One solution is to put:
    self.addCleanup(lambda: setattr(self.env.envs, 'envs', envs))
in SavepointCase's setup.

However in that case the reset is not needed at all:
it's necessary only if there were some modules to install.
Unfortunately to_install and to_uninstall are not symmetric:
to_uninstall contains only modules that should be uninstalled, whereas
to_install contains everything, and only filters later what actions
really need to be performed.

In this case, we can rely on the result of the installation process.
  • Loading branch information
len-odoo committed Dec 2, 2019
1 parent e9679d7 commit 5d94d86b27b8796ea65677fcb70f351eb306e54d
@@ -627,10 +627,9 @@ def execute(self):
if to_uninstall_modules:

installation_status = self._install_modules(to_install)

if to_install or to_uninstall_modules:
if installation_status or to_uninstall_modules:
# After the uninstall/install calls, the registry and environments
# are no longer valid. So we reset the environment.
@@ -43,3 +43,4 @@
from . import test_tests_tags
from . import test_base_document_layout
from . import test_form_create
from . import test_settings
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from unittest.mock import patch
from odoo.tests.common import TransactionCase

class TestSettings(TransactionCase):

def setUp(self):
super(TestSettings, self).setUp()

def just_raise(*args):
raise Exception("We should not be here.")
self.just_raise = just_raise

self.user = self.env.ref('base.user_admin') = self.env[''].create({'name': 'oobO'})
self.user.write({'company_ids': [(4,], 'company_id':})
Settings = self.env['res.config.settings'].with_user(
self.config = Settings.create({})

def test_no_install(self):
"""Make sure that when saving settings,
no modules are installed if nothing was set to install.
# check that no module should be installed in the first place
config_fields = self.config._get_classified_fields()
for name, module in config_fields['module']:
if int(self.config[name]):
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=self.just_raise):

def test_install(self):
"""Make sure that the previous test is valid, i.e. when saving settings,
it starts module install if something was set to install.
config_fields = self.config._get_classified_fields()
# set the first uninstalled module to install
module_to_install = next(filter(lambda m: m[1].state == 'uninstalled', config_fields['module']))
self.config[module_to_install[0]] = True

with self.assertRaisesRegex(Exception, "We should not be here."):
with patch('odoo.addons.base.models.ir_module.Module._button_immediate_function', new=self.just_raise):

0 comments on commit 5d94d86

Please sign in to comment.
You can’t perform that action at this time.