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.

add_subscriptions_backend: Add 'transaction.atomic' decorator.

Prakhar Pratyushd92eb77c9840
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 5684cd2af09..3269234381d 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -32,7 +32,7 @@ from django.apps import apps
from django.conf import settings
from django.core.mail import EmailMessage
from django.core.signals import got_request_exception
-from django.db import connection
+from django.db import connection, transaction
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import StateApps
from django.db.utils import IntegrityError
@@ -1458,13 +1458,17 @@ Output:
"invite_only": orjson.dumps(invite_only).decode(),
}
post_data.update(extra_post_data)
- result = self.api_post(
- user,
- "/api/v1/users/me/subscriptions",
- post_data,
- intentionally_undocumented=False,
- **extra,
- )
+ # We wrap the API call with a 'transaction.atomic()' context
+ # manager as it helps us with NOT rolling back the entire
+ # test transaction due to error responses.
+ with transaction.atomic():
+ result = self.api_post(
+ user,
+ "/api/v1/users/me/subscriptions",
+ post_data,
+ intentionally_undocumented=False,
+ **extra,
+ )
if not allow_fail:
self.assert_json_success(result)
return result
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 36891ce3427..b0a5488c843 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -533,6 +533,7 @@ RETENTION_DEFAULT: Union[str, int] = "realm_default"
EMPTY_PRINCIPALS: Union[Sequence[str], Sequence[int]] = []
[email protected](savepoint=False)
@require_non_guest_user
@has_request_variables
def add_subscriptions_backend(