Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
do_set_realm_property: Use transaction.atomic.
Mateusz Mandera0dd97eeaabd4
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex e2d5cd6a924..a1ca44f7dd1 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -843,6 +843,7 @@ def active_humans_in_realm(realm: Realm) -> Sequence[UserProfile]:return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)[email protected](savepoint=False)def do_set_realm_property(realm: Realm, name: str, value: Any, *, acting_user: Optional[UserProfile]) -> None:@@ -864,7 +865,7 @@ def do_set_realm_property(property=name,value=value,)- send_event(realm, event, active_user_ids(realm.id))+ transaction.on_commit(lambda: send_event(realm, event, active_user_ids(realm.id)))event_time = timezone_now()RealmAuditLog.objects.create(@@ -892,12 +893,14 @@ def do_set_realm_property(user_profiles = UserProfile.objects.filter(realm=realm, is_bot=False)for user_profile in user_profiles:user_profile.email = get_display_email_address(user_profile)- # TODO: Design a bulk event for this or force-reload all clients- send_user_email_update_event(user_profile)UserProfile.objects.bulk_update(user_profiles, ["email"])for user_profile in user_profiles:- flush_user_profile(sender=UserProfile, instance=user_profile)+ transaction.on_commit(+ lambda: flush_user_profile(sender=UserProfile, instance=user_profile)+ )+ # TODO: Design a bulk event for this or force-reload all clients+ send_user_email_update_event(user_profile)def do_set_realm_authentication_methods(diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 3cb35313749..5c05c58a9a0 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -329,12 +329,13 @@ class PermissionTest(ZulipTestCase):############################################################## Now, switch email address visibility, check client_gravatar# is automatically disabled for the user.- do_set_realm_property(- user.realm,- "email_address_visibility",- Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS,- acting_user=None,- )+ with self.captureOnCommitCallbacks(execute=True):+ do_set_realm_property(+ user.realm,+ "email_address_visibility",+ Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS,+ acting_user=None,+ )result = self.client_get("/json/users", {"client_gravatar": "true"})self.assert_json_success(result)members = result.json()["members"]