changeset 94997ed66e01 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=94997ed66e01
description:
        Prevent update configuration after modules are imported

        Modules can store copies of the configuration for performance reason so 
we must
        prevent to change the configuration after it happens.

        issue9679
        review318351002
diffstat:

 trytond/config.py |  14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diffs (45 lines):

diff -r 913a232cf7c2 -r 94997ed66e01 trytond/config.py
--- a/trytond/config.py Mon Oct 12 13:01:14 2020 +0200
+++ b/trytond/config.py Mon Oct 12 17:46:39 2020 +0200
@@ -4,6 +4,8 @@
 import configparser
 import urllib.parse
 import logging
+import sys
+from functools import wraps
 
 __all__ = ['config', 'get_hostname', 'get_port', 'split_netloc',
     'parse_listen', 'parse_uri']
@@ -37,6 +39,16 @@
     return urllib.parse.urlparse(uri)
 
 
+def before_modules(func):
+    @wraps(func)
+    def wrapper(*args, **kwargs):
+        if 'trytond.modules' in sys.modules:
+            raise RuntimeError(
+                "%s called after trytond.modules is imported" % func.__name__)
+        return func(*args, **kwargs)
+    return wrapper
+
+
 class TrytonConfigParser(configparser.ConfigParser):
 
     def __init__(self):
@@ -89,6 +101,7 @@
         self.update_environ()
         self.update_etc()
 
+    @before_modules
     def update_environ(self):
         for key, value in os.environ.items():
             if not key.startswith('TRYTOND_'):
@@ -101,6 +114,7 @@
                 self.add_section(section)
             self.set(section, option, value)
 
+    @before_modules
     def update_etc(self, configfile=os.environ.get('TRYTOND_CONFIG')):
         if isinstance(configfile, str):
             configfile = [configfile]

Reply via email to