From ec4c3f44cb9fd826826501918083386a8468194d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 14 Jun 2021 22:16:27 +0200 Subject: [PATCH] events: don't create system exception event in debug Signed-off-by: Jens Langhammer --- authentik/events/middleware.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/authentik/events/middleware.py b/authentik/events/middleware.py index 58be17c06..684121171 100644 --- a/authentik/events/middleware.py +++ b/authentik/events/middleware.py @@ -2,6 +2,7 @@ from functools import partial from typing import Callable +from django.conf import settings from django.db.models import Model from django.db.models.signals import post_save, pre_delete from django.http import HttpRequest, HttpResponse @@ -56,6 +57,11 @@ class AuditMiddleware: # pylint: disable=unused-argument def process_exception(self, request: HttpRequest, exception: Exception): """Disconnect handlers in case of exception""" + post_save.disconnect(dispatch_uid=LOCAL.authentik["request_id"]) + pre_delete.disconnect(dispatch_uid=LOCAL.authentik["request_id"]) + + if settings.DEBUG: + return thread = EventNewThread( EventAction.SYSTEM_EXCEPTION, request, @@ -63,9 +69,6 @@ class AuditMiddleware: ) thread.run() - post_save.disconnect(dispatch_uid=LOCAL.authentik["request_id"]) - pre_delete.disconnect(dispatch_uid=LOCAL.authentik["request_id"]) - @staticmethod # pylint: disable=unused-argument def post_save_handler(