From a105760123a122b4f439da8f7ae1a53653de6044 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 15 Dec 2021 16:44:22 +0100 Subject: [PATCH] events: improve app lookup for event creation Signed-off-by: Jens Langhammer --- authentik/events/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/authentik/events/models.py b/authentik/events/models.py index d08ab1e99..c10403488 100644 --- a/authentik/events/models.py +++ b/authentik/events/models.py @@ -2,7 +2,7 @@ import time from collections import Counter from datetime import timedelta -from inspect import getmodule, stack +from inspect import currentframe from smtplib import SMTPException from typing import TYPE_CHECKING, Optional, Type, Union from uuid import uuid4 @@ -192,14 +192,15 @@ class Event(ExpiringModel): def new( action: Union[str, EventAction], app: Optional[str] = None, - _inspect_offset: int = 1, **kwargs, ) -> "Event": """Create new Event instance from arguments. Instance is NOT saved.""" if not isinstance(action, EventAction): action = EventAction.CUSTOM_PREFIX + action if not app: - app = getmodule(stack()[_inspect_offset][0]).__name__ + current = currentframe() + parent = current.f_back + app = parent.f_globals["__name__"] cleaned_kwargs = cleanse_dict(sanitize_dict(kwargs)) event = Event(action=action, app=app, context=cleaned_kwargs) return event