From 3584bdf530edc3aa461864bad740fdf88d71fa76 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 31 Dec 2020 11:15:42 +0100 Subject: [PATCH] events: fix error when creating an even from policyrequests --- authentik/events/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/authentik/events/utils.py b/authentik/events/utils.py index 599b04ce9..080acf3c1 100644 --- a/authentik/events/utils.py +++ b/authentik/events/utils.py @@ -11,6 +11,7 @@ from django.views.debug import SafeExceptionReporterFilter from guardian.utils import get_anonymous_user from authentik.core.models import User +from authentik.policies.types import PolicyRequest # Special keys which are *not* cleaned, even when the default filter # is matched @@ -74,6 +75,11 @@ def sanitize_dict(source: Dict[Any, Any]) -> Dict[Any, Any]: final_dict = {} for key, value in source.items(): if is_dataclass(value): + # Because asdict calls `copy.deepcopy(obj)` on everything thats not tuple/dict, + # and deepcopy doesn't work with HttpRequests (neither django nor rest_framework). + # Currently, the only dataclass that actually holds an http request is a PolicyRequest + if isinstance(value, PolicyRequest): + value.http_request = None value = asdict(value) if isinstance(value, dict): final_dict[key] = sanitize_dict(value)