Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Prakhar Pratyush0e67e4f1a144
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index 8321bc651da..46c8eb6ef9a 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -9,6 +9,7 @@ from unittest import mock
import orjson
from django.conf import settings
from django.core.exceptions import ValidationError
+from django.db import transaction
from django.http import HttpResponse
from django.utils.timezone import now as timezone_now
from typing_extensions import override
@@ -4016,7 +4017,9 @@ class SubscriptionRestApiTest(ZulipTestCase):
def thunk2() -> HttpResponse:
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])
user_profile = self.example_user("hamlet")
diff --git a/zerver/transaction_tests/test_user_groups.py b/zerver/transaction_tests/test_user_groups.py
index 3b5f6be3250..1cdeff32ec1 100644
--- a/zerver/transaction_tests/test_user_groups.py
+++ b/zerver/transaction_tests/test_user_groups.py
@@ -28,7 +28,6 @@ def dev_update_subgroups(
assert BARRIER is not None
try:
with (
- transaction.atomic(),
mock.patch("zerver.lib.user_groups.access_user_group_for_update") as m,
):
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index d618d473e55..6f0246cba5b 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -468,7 +468,7 @@ def compose_views(thunks: list[Callable[[], HttpResponse]]) -> dict[str, Any]:
"""
json_dict: dict[str, Any] = {}
- with transaction.atomic():
+ with transaction.atomic(savepoint=False):
for thunk in thunks:
response = thunk()
json_dict.update(orjson.loads(response.content))
diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py
index 2f44c2be18c..98e0d0bf642 100644
--- a/zerver/views/user_groups.py
+++ b/zerver/views/user_groups.py
@@ -468,6 +468,7 @@ def remove_subgroups_from_group_backend(
@require_member_or_admin
@typed_endpoint
[email protected](durable=True)
def update_subgroups_of_user_group(
request: HttpRequest,
user_profile: UserProfile,