From d7fdca1b445d92975330724c58c2c4270c21e91c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 15 Sep 2021 09:50:11 +0200 Subject: [PATCH] stages/email: fix error when retrying email delivery after stage has been deleted Signed-off-by: Jens Langhammer --- authentik/stages/email/tasks.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/authentik/stages/email/tasks.py b/authentik/stages/email/tasks.py index d08da9683..93cec2538 100644 --- a/authentik/stages/email/tasks.py +++ b/authentik/stages/email/tasks.py @@ -54,7 +54,16 @@ def send_mail(self: MonitoredTask, message: dict[Any, Any], email_stage_pk: Opti if not email_stage_pk: stage: EmailStage = EmailStage(use_global_settings=True) else: - stage: EmailStage = EmailStage.objects.get(pk=email_stage_pk) + stages = EmailStage.objects.filter(pk=email_stage_pk) + if not stages.exists(): + self.set_status( + TaskResult( + TaskResultStatus.WARNING, + messages=["Email stage does not exist anymore. Discarding message."], + ) + ) + return + stage: EmailStage = stages.first() try: backend = stage.backend except ValueError as exc: