django_api: Rename 'send_event' to 'send_event_rollback_unsafe'.

This commit renames the 'send_event' function to
'send_event_rollback_unsafe' to reflect the fact that it doesn't
wait for the db transaction (within which it gets called, if any)
to commit and sends event irrespective of commit or rollback.

In most of the cases we don't want to send event in the case of
rollbacks, so the caller should be aware that calling the function
directly is rollback unsafe.
This commit is contained in:
Prakhar Pratyush
2024-09-13 14:06:58 +05:30
committed by Tim Abbott
parent 8e71806958
commit e763d065a3
12 changed files with 41 additions and 35 deletions

View File

@@ -2052,11 +2052,11 @@ class ZulipTestCase(ZulipTestCaseMixin, TestCase):
# So explicitly change parameter name to 'notice' to work around this problem
with (
mock.patch("zerver.tornado.event_queue.process_notification", lst.append),
# Some `send_event` calls need to be executed only after the current transaction
# commits (using `on_commit` hooks). Because the transaction in Django tests never
# commits (rather, gets rolled back after the test completes), such events would
# never be sent in tests, and we would be unable to verify them. Hence, we use
# this helper to make sure the `send_event` calls actually run.
# Some `send_event_rollback_unsafe` calls need to be executed only after the
# current transaction commits (using `on_commit` hooks). Because the transaction
# in Django tests never commits (rather, gets rolled back after the test completes),
# such events would never be sent in tests, and we would be unable to verify them.
# Hence, we use this helper to make sure the `send_event_rollback_unsafe` calls actually run.
self.captureOnCommitCallbacks(execute=True),
):
yield lst