From d52dc594f5eaddd58e412b629e824668ba810ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Feb 2020 23:18:19 +0100 Subject: [PATCH] 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 --- trytond/model/dictschema.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/trytond/model/dictschema.py b/trytond/model/dictschema.py index f03e865abf..d468f6aac7 100644 --- a/trytond/model/dictschema.py +++ b/trytond/model/dictschema.py @@ -70,6 +70,7 @@ class DictSchemaMixin(object): ['selection', 'multiselection']), }, depends=['type_']), 'get_selection_json') + _relation_fields_cache = Cache('_dict_schema_mixin.get_relation_fields') @classmethod def __setup__(cls): @@ -77,10 +78,6 @@ class DictSchemaMixin(object): 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(): @@ -167,12 +164,12 @@ class DictSchemaMixin(object): 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