details: https://code.tryton.org/tryton/commit/d4fb2224e875
branch: 8.0
user: Cédric Krier <[email protected]>
date: Wed Aug 12 17:57:01 2026 +0200
description:
Register cache instance after being fully initialized
Otherwise an instance can be accessed by another thread via the
registry when
it is still being initialized. And it may crash on missing attribute.
Closes #15007
(grafted from f1840545f4eb5ae5c870a2557a7c3a0314fedb16)
diffstat:
trytond/trytond/cache.py | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diffs (29 lines):
diff -r 6b85c5273d29 -r d4fb2224e875 trytond/trytond/cache.py
--- a/trytond/trytond/cache.py Tue Aug 11 12:02:09 2026 +0200
+++ b/trytond/trytond/cache.py Wed Aug 12 17:57:01 2026 +0200
@@ -83,7 +83,15 @@
self.portable_id = str(uuid4())
-class BaseCache(object):
+class _CacheMeta(type):
+ def __call__(cls, *args, **kwargs):
+ inst = super().__call__(*args, **kwargs)
+ assert inst._name not in BaseCache._instances, inst._name
+ BaseCache._instances[inst._name] = inst
+ return inst
+
+
+class BaseCache(metaclass=_CacheMeta):
_instances = {}
context_ignored_keys = {
'client', '_request', '_check_access', '_skip_warnings',
@@ -112,8 +120,6 @@
self.duration = dt.timedelta(**duration)
else:
self.duration = None
- assert self._name not in self._instances, self._name
- self._instances[self._name] = self
@classmethod
def stats(cls):