events: handle error when notifications are triggered and no users exist

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-06 20:13:04 +02:00
parent d51ecc4554
commit 6c3b7c8d3e
1 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,13 @@ def event_trigger_handler(event_uuid: str, trigger_name: str):
return return
LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger) LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger)
user = User.objects.filter(pk=event.user.get("pk")).first() or get_anonymous_user() try:
user = (
User.objects.filter(pk=event.user.get("pk")).first() or get_anonymous_user()
)
except User.DoesNotExist:
LOGGER.warning("e(trigger): failed to get user", trigger=trigger)
return
policy_engine = PolicyEngine(trigger, user) policy_engine = PolicyEngine(trigger, user)
policy_engine.mode = PolicyEngineMode.MODE_ANY policy_engine.mode = PolicyEngineMode.MODE_ANY
policy_engine.empty_result = False policy_engine.empty_result = False