events: don't create system exception event in debug

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-14 22:16:27 +02:00
parent f10bd432b3
commit ec4c3f44cb
1 changed files with 6 additions and 3 deletions

View File

@ -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(