Do not fails to clear password from cache if there is no cache

This was introduced in 7b5157206d32

Closes #12165
This commit is contained in:
Cédric Krier committed 2023-03-30 22:36:18 +02:00
1 parent 1b6644a9a5
commit f40cea7507
1 file changed
+12 -10
+12 -10
View File
@@ -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