stages/email: fix error when retrying email delivery after stage has been deleted

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-15 09:50:11 +02:00
parent 37346763dc
commit d7fdca1b44
1 changed files with 10 additions and 1 deletions

View File

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