diff --git a/zerver/actions/scheduled_messages.py b/zerver/actions/scheduled_messages.py index ab9239d90a..748fce7286 100644 --- a/zerver/actions/scheduled_messages.py +++ b/zerver/actions/scheduled_messages.py @@ -24,7 +24,7 @@ from zerver.lib.scheduled_messages import access_scheduled_message from zerver.lib.string_validation import check_stream_topic from zerver.models import Client, Realm, ScheduledMessage, Subscription, UserProfile from zerver.models.users import get_system_bot -from zerver.tornado.django_api import send_event +from zerver.tornado.django_api import send_event, send_event_on_commit SCHEDULED_MESSAGE_LATE_CUTOFF_MINUTES = 10 @@ -104,14 +104,15 @@ def do_schedule_messages( scheduled_message.has_attachment = True scheduled_message.save(update_fields=["has_attachment"]) - event = { - "type": "scheduled_messages", - "op": "add", - "scheduled_messages": [ - scheduled_message.to_dict() for scheduled_message, ignored in scheduled_messages - ], - } - send_event(sender.realm, event, [sender.id]) + event = { + "type": "scheduled_messages", + "op": "add", + "scheduled_messages": [ + scheduled_message.to_dict() for scheduled_message, ignored in scheduled_messages + ], + } + send_event_on_commit(sender.realm, event, [sender.id]) + return [scheduled_message.id for scheduled_message, ignored in scheduled_messages]