[FIX] server_environment_ir_config_parameter

fix a conflict between this module and mail which overrides the reading
of some mail related system parameters
This commit is contained in:
Alexandre Fayolle 2021-12-22 16:14:53 +01:00 committed by Jessica Schreiber
parent a652e1690e
commit 77a229e914
2 changed files with 29 additions and 5 deletions

View File

@ -39,8 +39,18 @@ class IrConfigParameter(models.Model):
# should we have preloaded values in database at,
# server startup, modules loading their parameters
# from data files would break on unique key error.
self.sudo().set_param(key, cvalue)
value = cvalue
if not self.env.context.get("_from_get_param", 0):
# the check is to avoid recursion, for instance the mail
# addon has an override in ir.config_parameter::write which
# calls get_param if we are setting mail.catchall.alias and
# this will cause an infinite recursion. We cut that
# recursion by using the context check.
#
# The mail addon call to get_param expects to get the value
# *before* the change, so we have to return the database
# value in that case
self.sudo().with_context(_from_get_param=1).set_param(key, cvalue)
value = cvalue
if value is None:
return default
return value

View File

@ -14,9 +14,10 @@ class TestEnv(ServerEnvironmentCase):
def setUp(self):
super().setUp()
self.ICP = self.env["ir.config_parameter"]
self.env_config = (
"[ir.config_parameter]\n" "ircp_from_config=config_value\n" "ircp_empty=\n"
)
self.env_config = """[ir.config_parameter]
ircp_from_config=config_value
ircp_empty=
mail.catchall.alias=my_alias"""
def _load_xml(self, module, filepath):
convert_file(
@ -102,3 +103,16 @@ class TestEnv(ServerEnvironmentCase):
)
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")
def test_read_mail_catchall_alias(self):
"""read mail.catchall.alias from server env:
this must not break the mail addon's overload"""
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
value = self.ICP.get_param("mail.catchall.alias")
self.assertEqual(value, "my_alias")
res = self.ICP.search([("key", "=", "mail.catchall.alias")])
self.assertEqual(len(res), 1)
self.assertEqual(res.value, "my_alias")