From cefc1a57eef13d93125f643fb9734475c936d6ff Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 13 Feb 2023 13:18:04 +0100 Subject: [PATCH] core: handle error when cleaning up sessions and cached session can't be loaded Signed-off-by: Jens Langhammer --- authentik/admin/api/tasks.py | 3 ++- authentik/core/tasks.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/authentik/admin/api/tasks.py b/authentik/admin/api/tasks.py index 684344be2..00fbe4e08 100644 --- a/authentik/admin/api/tasks.py +++ b/authentik/admin/api/tasks.py @@ -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() diff --git a/authentik/core/tasks.py b/authentik/core/tasks.py index 14dbd8b60..9f7d73b10 100644 --- a/authentik/core/tasks.py +++ b/authentik/core/tasks.py @@ -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