[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:
parent
a652e1690e
commit
77a229e914
|
|
@ -39,7 +39,17 @@ class IrConfigParameter(models.Model):
|
||||||
# should we have preloaded values in database at,
|
# should we have preloaded values in database at,
|
||||||
# server startup, modules loading their parameters
|
# server startup, modules loading their parameters
|
||||||
# from data files would break on unique key error.
|
# from data files would break on unique key error.
|
||||||
self.sudo().set_param(key, 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
|
value = cvalue
|
||||||
if value is None:
|
if value is None:
|
||||||
return default
|
return default
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,10 @@ class TestEnv(ServerEnvironmentCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.ICP = self.env["ir.config_parameter"]
|
self.ICP = self.env["ir.config_parameter"]
|
||||||
self.env_config = (
|
self.env_config = """[ir.config_parameter]
|
||||||
"[ir.config_parameter]\n" "ircp_from_config=config_value\n" "ircp_empty=\n"
|
ircp_from_config=config_value
|
||||||
)
|
ircp_empty=
|
||||||
|
mail.catchall.alias=my_alias"""
|
||||||
|
|
||||||
def _load_xml(self, module, filepath):
|
def _load_xml(self, module, filepath):
|
||||||
convert_file(
|
convert_file(
|
||||||
|
|
@ -102,3 +103,16 @@ class TestEnv(ServerEnvironmentCase):
|
||||||
)
|
)
|
||||||
value = self.ICP.get_param("ircp_from_config")
|
value = self.ICP.get_param("ircp_from_config")
|
||||||
self.assertEqual(value, "config_value")
|
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")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue