changeset 861c92e544d6 in trytond:5.4
details: https://hg.tryton.org/trytond?cmd=changeset;node=861c92e544d6
description:
        Use a single instance to cache get_relation_fields

        It is wrong to instantiate the cache in the __setup__ because it can be 
run
        multiple time in the same process (but with new pooled classes).

        issue9019
        review253011003
        (grafted from d50600d2a90df8ecc4b8488fed7a6e8d9ab3187c)
diffstat:

 trytond/model/dictschema.py |  9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diffs (37 lines):

diff -r fffbeae5756f -r 861c92e544d6 trytond/model/dictschema.py
--- a/trytond/model/dictschema.py       Mon Feb 10 23:13:26 2020 +0100
+++ b/trytond/model/dictschema.py       Mon Feb 10 23:18:19 2020 +0100
@@ -63,6 +63,7 @@
                 'invisible': Eval('type_') != 'selection',
                 },
             depends=['type_']), 'get_selection_json')
+    _relation_fields_cache = Cache('_dict_schema_mixin.get_relation_fields')
 
     @classmethod
     def __setup__(cls):
@@ -70,10 +71,6 @@
         cls.__rpc__.update({
                 'get_keys': RPC(instantiate=0),
                 })
-        # Do not instantiate more than one Cache
-        if not hasattr(cls, '_relation_fields_cache'):
-            cls._relation_fields_cache = Cache(
-                cls.__name__ + '.get_relation_fields')
 
     @staticmethod
     def default_digits():
@@ -154,12 +151,12 @@
     def get_relation_fields(cls):
         if not config.get('dict', cls.__name__, default=True):
             return {}
-        fields = cls._relation_fields_cache.get(None)
+        fields = cls._relation_fields_cache.get(cls.__name__)
         if fields is not None:
             return fields
         keys = cls.get_keys(cls.search([]))
         fields = {k['name']: k for k in keys}
-        cls._relation_fields_cache.set(None, fields)
+        cls._relation_fields_cache.set(cls.__name__, fields)
         return fields
 
     @classmethod

Reply via email to