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.

custom_check: Add rule to avoid creating savepoints.

Prakhar Pratyushc5b3d2e43496
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index ed5781a39a8..45abe4ee82b 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1816,7 +1816,7 @@ class BillingSession(ABC):
)
# TODO: The correctness of this relies on user creation, deactivation, etc being
- # in a transaction.atomic() with the relevant RealmAuditLog entries
+ # in a transaction.atomic block with the relevant RealmAuditLog entries
with transaction.atomic(durable=True):
# We get the current license count here in case the number of billable
# licenses has changed since the upgrade process began.
diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py
index b8ba0a91dc3..5560b141af5 100644
--- a/tools/linter_lib/custom_check.py
+++ b/tools/linter_lib/custom_check.py
@@ -462,8 +462,23 @@ python_rules = RuleList(
"description": 'A mock function is missing a leading "assert_"',
},
{
- "pattern": "@transaction.atomic\\(\\)",
- "description": "Use @transaction.atomic as function decorator for consistency.",
+ "pattern": r"transaction\.atomic$|transaction\.atomic\(\)|savepoint=True",
+ "description": "Use 'durable=True' or 'savepoint=False' argument explicitly to avoid the possibility of creating savepoints.",
+ "exclude": {"confirmation/migrations/", "zerver/migrations/", "zilencer/migrations/"},
+ "exclude_line": {
+ (
+ "zerver/actions/create_user.py",
+ "with suppress(IntegrityError), transaction.atomic(savepoint=True):",
+ ),
+ (
+ "zerver/lib/test_classes.py",
+ "with transaction.atomic(savepoint=True):",
+ ),
+ (
+ "zerver/tests/test_subs.py",
+ "with transaction.atomic(savepoint=True), self.assertRaises(JsonableError):",
+ ),
+ },
},
*whitespace_rules,
*shebang_rules,
diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py
index f64a185606d..eb7c19535dc 100644
--- a/zerver/lib/retention.py
+++ b/zerver/lib/retention.py
@@ -132,7 +132,7 @@ def run_archiving(
# archived-and-deleted or not transactionally.
#
# We implement this design by executing queries that archive messages and their related objects
- # (such as UserMessage, Reaction, and Attachment) inside the same transaction.atomic() block.
+ # (such as UserMessage, Reaction, and Attachment) inside the same transaction.atomic block.
assert type in (ArchiveTransaction.MANUAL, ArchiveTransaction.RETENTION_POLICY_BASED)
if chunk_size is not None: