From f40cea75071d32def95692cec43dc288d07f5e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 30 Mar 2023 22:36:18 +0200 Subject: [PATCH] Do not fails to clear password from cache if there is no cache This was introduced in 7b5157206d32 Closes #12165 --- trytond/trytond/res/user.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/trytond/trytond/res/user.py b/trytond/trytond/res/user.py index 0c3908ae09..11758b9820 100644 --- a/trytond/trytond/res/user.py +++ b/trytond/trytond/res/user.py @@ -364,12 +364,13 @@ class User(avatar_mixin(100, 'login'), DeactivableMixin, ModelSQL, ModelView): @classmethod def read(cls, ids, fields_names): result = super(User, cls).read(ids, fields_names) - cache = Transaction().get_cache()[cls.__name__] - for values in result: - if 'password_hash' in values: - values['password_hash'] = None - if values['id'] in cache: - cache[values['id']]['password_hash'] = None + cache = Transaction().get_cache().get(cls.__name__) + if cache is not None: + for values in result: + if 'password_hash' in values: + values['password_hash'] = None + if values['id'] in cache: + cache[values['id']]['password_hash'] = None return result @classmethod @@ -379,11 +380,12 @@ class User(avatar_mixin(100, 'login'), DeactivableMixin, ModelSQL, ModelView): users = super().search( domain, offset=offset, limit=limit, order=order, count=count, query=query) - cache = Transaction().get_cache()[cls.__name__] if not count and not query: - for user in users: - if user.id in cache: - cache[user.id]['password_hash'] = None + cache = Transaction().get_cache().get(cls.__name__) + if cache is not None: + for user in users: + if user.id in cache: + cache[user.id]['password_hash'] = None return users @classmethod