zulip_updates: Protect against race with ourself.

This commit is contained in:
Tim Abbott 2024-04-18 12:13:10 -07:00
parent 5565bcf64f
commit 5c5e6b8cc5
1 changed files with 9 additions and 0 deletions

View File

@ -193,7 +193,16 @@ def send_zulip_update_announcements(skip_delay: bool) -> None:
)
for realm in realms:
# Refresh the realm from the database and check its
# properties, to protect against racing with another copy of
# ourself.
realm.refresh_from_db()
realm_zulip_update_announcements_level = realm.zulip_update_announcements_level
assert (
realm_zulip_update_announcements_level is None
or realm_zulip_update_announcements_level < latest_zulip_update_announcements_level
)
sender = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
messages = []