email_senders: Handle a None realm_id.

Some codepaths send an event with `realm_id=None` -- which we still
must trim out of the event, even if we do not add a `realm` value for
them.
This commit is contained in:
Alex Vandiver
2025-05-22 14:52:57 +00:00
committed by Tim Abbott
parent 42360c9477
commit 198a5a8294

View File

@@ -64,9 +64,10 @@ class EmailSendingWorker(LoopQueueProcessingWorker):
if "failed_tries" in copied_event:
del copied_event["failed_tries"]
handle_send_email_format_changes(copied_event)
if copied_event.get("realm_id") is not None:
if "realm_id" in copied_event:
# "realm" does not serialize over the queue, so we send the realm_id
copied_event["realm"] = Realm.objects.get(id=copied_event["realm_id"])
if copied_event.get("realm_id") is not None:
copied_event["realm"] = Realm.objects.get(id=copied_event["realm_id"])
del copied_event["realm_id"]
self.connection = initialize_connection(self.connection)
send_immediate_email(**copied_event, connection=self.connection)