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.
This commit is contained in:
Prakhar Pratyush 2024-11-01 16:42:53 +05:30 committed by Tim Abbott
parent 9371bdb81d
commit 0fb5657131
7 changed files with 11 additions and 11 deletions

View File

@ -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:

View File

@ -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

View File

@ -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.

View File

@ -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:

View File

@ -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,

View File

@ -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,

View File

@ -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: