From bae6188d92b10c93aa2a6c6b8655a7bd89578b5d Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 9 Aug 2024 16:00:44 +0530 Subject: [PATCH] user_groups: Add transaction.atomic decorator to add_user_group view. The database operations in 'access_user_group_for_setting' and 'check_add_user_group' used in 'add_user_group' view should be collectively atomic. This commit adds transaction.atomic decorator for that purpose. --- zerver/actions/user_groups.py | 6 +++--- zerver/views/user_groups.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/actions/user_groups.py b/zerver/actions/user_groups.py index e3e2bcc1d8..753f6b3dba 100644 --- a/zerver/actions/user_groups.py +++ b/zerver/actions/user_groups.py @@ -26,7 +26,7 @@ from zerver.models import ( ) from zerver.models.groups import SystemGroups from zerver.models.users import active_user_ids -from zerver.tornado.django_api import send_event, send_event_on_commit +from zerver.tornado.django_api import send_event_on_commit class MemberGroupUserDict(TypedDict): @@ -35,7 +35,7 @@ class MemberGroupUserDict(TypedDict): date_joined: datetime -@transaction.atomic +@transaction.atomic(savepoint=False) def create_user_group_in_database( name: str, members: list[UserProfile], @@ -182,7 +182,7 @@ def do_send_create_user_group_event( can_mention_group=get_group_setting_value_for_api(user_group.can_mention_group), ), ) - send_event(user_group.realm, event, active_user_ids(user_group.realm_id)) + send_event_on_commit(user_group.realm, event, active_user_ids(user_group.realm_id)) def check_add_user_group( diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 086bd5a73b..c0d084ca47 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -45,6 +45,7 @@ from zerver.models.users import get_system_bot from zerver.views.streams import compose_views +@transaction.atomic(durable=True) @require_user_group_edit_permission @typed_endpoint def add_user_group(