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)