handle_missedmessage_emails: Update codepath to queue event on commit.

Earlier, in 'handle_missedmessage_emails' codepath we were using
'queue_json_publish' which can lead to a situation where we enqueue
events but the transaction fails at a later stage.

Events should not be published until we know we're not rolling back.
This commit is contained in:
Prakhar Pratyush
2024-12-04 13:59:38 +05:30
committed by Tim Abbott
parent f0cbce564d
commit 4bef1a510c
5 changed files with 36 additions and 28 deletions

View File

@@ -49,6 +49,7 @@ from zerver.actions.realm_settings import (
from zerver.actions.streams import bulk_add_subscriptions, bulk_remove_subscriptions
from zerver.decorator import do_two_factor_login
from zerver.lib.cache import bounce_key_prefix_for_testing
from zerver.lib.email_notifications import MissedMessageData, handle_missedmessage_emails
from zerver.lib.initial_password import initial_password
from zerver.lib.mdiff import diff_strings
from zerver.lib.message import access_message
@@ -2241,6 +2242,12 @@ class ZulipTestCase(ZulipTestCaseMixin, TestCase):
# immediately run the worker for it, producing the thumbnails.
return self.upload_image(image_name)
def handle_missedmessage_emails(
self, user_profile_id: int, message_ids: dict[int, MissedMessageData]
) -> None:
with self.captureOnCommitCallbacks(execute=True):
handle_missedmessage_emails(user_profile_id, message_ids)
def get_row_ids_in_all_tables() -> Iterator[tuple[str, set[int]]]:
all_models = apps.get_models(include_auto_created=True)