compose_views: Add `savepoint=False` to avoid creating savepoints.

'compose_views' is used inside an outer db transaction created in
'update_user_group_backend'.

`transaction.atomic()` block in 'compose_views' resulted in
savepoint creation.

This commit adds `savepoint=False` to avoid that.
This commit is contained in:
Prakhar Pratyush 2024-11-04 11:02:53 +05:30 committed by Tim Abbott
parent 9c9866461a
commit 0e67e4f1a1
4 changed files with 6 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from unittest import mock
import orjson import orjson
from django.conf import settings from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import transaction
from django.http import HttpResponse from django.http import HttpResponse
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from typing_extensions import override from typing_extensions import override
@ -4016,7 +4017,9 @@ class SubscriptionRestApiTest(ZulipTestCase):
def thunk2() -> HttpResponse: def thunk2() -> HttpResponse:
raise JsonableError("random failure") raise JsonableError("random failure")
with self.assertRaises(JsonableError): with transaction.atomic(), self.assertRaises(JsonableError):
# The atomic() wrapper helps to avoid JsonableError breaking
# the test's transaction.
compose_views([thunk1, thunk2]) compose_views([thunk1, thunk2])
user_profile = self.example_user("hamlet") user_profile = self.example_user("hamlet")

View File

@ -28,7 +28,6 @@ def dev_update_subgroups(
assert BARRIER is not None assert BARRIER is not None
try: try:
with ( with (
transaction.atomic(),
mock.patch("zerver.lib.user_groups.access_user_group_for_update") as m, mock.patch("zerver.lib.user_groups.access_user_group_for_update") as m,
): ):

View File

@ -468,7 +468,7 @@ def compose_views(thunks: list[Callable[[], HttpResponse]]) -> dict[str, Any]:
""" """
json_dict: dict[str, Any] = {} json_dict: dict[str, Any] = {}
with transaction.atomic(): with transaction.atomic(savepoint=False):
for thunk in thunks: for thunk in thunks:
response = thunk() response = thunk()
json_dict.update(orjson.loads(response.content)) json_dict.update(orjson.loads(response.content))

View File

@ -468,6 +468,7 @@ def remove_subgroups_from_group_backend(
@require_member_or_admin @require_member_or_admin
@typed_endpoint @typed_endpoint
@transaction.atomic(durable=True)
def update_subgroups_of_user_group( def update_subgroups_of_user_group(
request: HttpRequest, request: HttpRequest,
user_profile: UserProfile, user_profile: UserProfile,