From 0fb5657131df30c21a62e3583e60d295191f18d8 Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 1 Nov 2024 16:42:53 +0530 Subject: [PATCH] transaction: Add durable=True to outermost transaction.atomic decorator. This commit adds 'durable=True' to the outermost transactions of the following functions: * do_create_multiuse_invite_link * do_revoke_user_invite * do_revoke_multi_use_invite * sync_ldap_user_data * do_reactivate_remote_server * do_deactivate_remote_server * bulk_handle_digest_email * handle_customer_migration_from_server_to_realm * add_reaction * remove_reaction * deactivate_user_group It helps to avoid creating unintended savepoints in the future. This is as a part of our plan to explicitly mark all the transaction.atomic decorators with either 'savepoint=False' or 'durable=True' as required. * 'savepoint=True' is used in special cases. --- corporate/lib/stripe.py | 4 ++-- zerver/actions/invites.py | 6 +++--- zerver/lib/digest.py | 2 +- zerver/management/commands/sync_ldap_user_data.py | 2 +- zerver/views/reactions.py | 4 ++-- zerver/views/user_groups.py | 2 +- zilencer/views.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index a6d585a406..381e06cb73 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -5231,7 +5231,7 @@ def ensure_customer_does_not_have_active_plan(customer: Customer) -> None: raise UpgradeWithExistingPlanError -@transaction.atomic +@transaction.atomic(durable=True) def do_reactivate_remote_server(remote_server: RemoteZulipServer) -> None: """ Utility function for reactivating deactivated registrations. @@ -5253,7 +5253,7 @@ def do_reactivate_remote_server(remote_server: RemoteZulipServer) -> None: ) -@transaction.atomic +@transaction.atomic(durable=True) def do_deactivate_remote_server( remote_server: RemoteZulipServer, billing_session: RemoteServerBillingSession ) -> None: diff --git a/zerver/actions/invites.py b/zerver/actions/invites.py index 11534c7127..e2c783dcae 100644 --- a/zerver/actions/invites.py +++ b/zerver/actions/invites.py @@ -362,7 +362,7 @@ def do_get_invites_controlled_by_user(user_profile: UserProfile) -> list[dict[st return invites -@transaction.atomic +@transaction.atomic(durable=True) def do_create_multiuse_invite_link( referred_by: UserProfile, invited_as: int, @@ -386,7 +386,7 @@ def do_create_multiuse_invite_link( ) -@transaction.atomic +@transaction.atomic(durable=True) def do_revoke_user_invite(prereg_user: PreregistrationUser) -> None: email = prereg_user.email realm = prereg_user.realm @@ -403,7 +403,7 @@ def do_revoke_user_invite(prereg_user: PreregistrationUser) -> None: notify_invites_changed(realm, changed_invite_referrer=prereg_user.referred_by) -@transaction.atomic +@transaction.atomic(durable=True) def do_revoke_multi_use_invite(multiuse_invite: MultiuseInvite) -> None: realm = multiuse_invite.referred_by.realm diff --git a/zerver/lib/digest.py b/zerver/lib/digest.py index f233017cf0..69f5cd7fd9 100644 --- a/zerver/lib/digest.py +++ b/zerver/lib/digest.py @@ -387,7 +387,7 @@ def get_digest_context(user: UserProfile, cutoff: float) -> dict[str, Any]: raise AssertionError("Unreachable") -@transaction.atomic +@transaction.atomic(durable=True) def bulk_handle_digest_email(user_ids: list[int], cutoff: float) -> None: # We go directly to the database to get user objects, # since inactive users are likely to not be in the cache. diff --git a/zerver/management/commands/sync_ldap_user_data.py b/zerver/management/commands/sync_ldap_user_data.py index 5b885e364d..0f4f14f57b 100644 --- a/zerver/management/commands/sync_ldap_user_data.py +++ b/zerver/management/commands/sync_ldap_user_data.py @@ -19,7 +19,7 @@ log_to_file(logger, settings.LDAP_SYNC_LOG_PATH) # Run this on a cron job to pick up on name changes. -@transaction.atomic +@transaction.atomic(durable=True) def sync_ldap_user_data( user_profiles: QuerySet[UserProfile], deactivation_protection: bool = True ) -> None: diff --git a/zerver/views/reactions.py b/zerver/views/reactions.py index c1b9c92597..55ad9c91bb 100644 --- a/zerver/views/reactions.py +++ b/zerver/views/reactions.py @@ -12,7 +12,7 @@ from zerver.models import Reaction, UserProfile # transaction.atomic is required since we use FOR UPDATE queries in access_message -@transaction.atomic +@transaction.atomic(durable=True) @typed_endpoint def add_reaction( request: HttpRequest, @@ -29,7 +29,7 @@ def add_reaction( # transaction.atomic is required since we use FOR UPDATE queries in access_message -@transaction.atomic +@transaction.atomic(durable=True) @typed_endpoint def remove_reaction( request: HttpRequest, diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index ae2473ec42..2f44c2be18 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -207,7 +207,7 @@ def edit_user_group( @typed_endpoint -@transaction.atomic +@transaction.atomic(durable=True) def deactivate_user_group( request: HttpRequest, user_profile: UserProfile, diff --git a/zilencer/views.py b/zilencer/views.py index 8bc6c96261..fb3ec2aea7 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -1035,7 +1035,7 @@ def get_human_user_realm_uuids( return billable_realm_uuids -@transaction.atomic +@transaction.atomic(durable=True) def handle_customer_migration_from_server_to_realm( server: RemoteZulipServer, ) -> None: