From 69a2775e9bc10a02752bcd0458645919e77205f3 Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 9 Aug 2024 12:46:18 +0530 Subject: [PATCH] video_calls: Update do_set_zoom_token to send event on commit. Earlier, we were using 'send_event' in 'do_set_zoom_token' which can lead to a situation, if any db operation is added after the 'send_event' in future, where we enqueue events but the action function fails at a later stage. Events should not be sent until we know we're not rolling back. Fixes part of #30489. --- zerver/actions/video_calls.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/actions/video_calls.py b/zerver/actions/video_calls.py index d4c8603cd9..23f99c0b25 100644 --- a/zerver/actions/video_calls.py +++ b/zerver/actions/video_calls.py @@ -1,11 +1,14 @@ +from django.db import transaction + from zerver.models import UserProfile -from zerver.tornado.django_api import send_event +from zerver.tornado.django_api import send_event_on_commit +@transaction.atomic(durable=True) def do_set_zoom_token(user: UserProfile, token: dict[str, object] | None) -> None: user.zoom_token = token user.save(update_fields=["zoom_token"]) - send_event( + send_event_on_commit( user.realm, dict(type="has_zoom_token", value=token is not None), [user.id],