core: handle error when cleaning up sessions and cached session can't be loaded

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-02-13 13:18:04 +01:00
parent 53b25d61f7
commit cefc1a57ee
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View File

@ -50,7 +50,8 @@ class TaskSerializer(PassiveSerializer):
are pickled in cache. In that case, just delete the info"""
try:
return super().to_representation(instance)
except AttributeError: # pragma: no cover
# pylint: disable=broad-except
except Exception: # pragma: no cover
if isinstance(self.instance, list):
for inst in self.instance:
inst.delete()

View File

@ -43,7 +43,11 @@ def clean_expired_models(self: MonitoredTask):
amount = 0
for session in AuthenticatedSession.objects.all():
cache_key = f"{KEY_PREFIX}{session.session_key}"
value = cache.get(cache_key)
try:
value = cache.get(cache_key)
# pylint: disable=broad-except
except Exception as exc:
LOGGER.debug("Failed to get session from cache", exc=exc)
if not value:
session.delete()
amount += 1