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.

semgrep: Check if a batched migration is made atomic.

Zixuan James Li119cf9100c99
diff --git a/tools/semgrep.yml b/tools/semgrep.yml
index 975d1959d38..818805fc1b4 100644
--- a/tools/semgrep.yml
+++ b/tools/semgrep.yml
@@ -134,3 +134,22 @@ rules:
- zerver/tests/
message: "Do not fetch a Confirmation object directly, use get_object_from_key instead"
severity: ERROR
+
+ - id: dont-make-batched-migration-atomic
+ patterns:
+ - pattern: |
+ class Migration(migrations.Migration):
+ ...
+ - pattern-inside: |
+ ...
+ BATCH_SIZE = ...
+ ...
+ - pattern-not: |
+ class Migration(migrations.Migration):
+ atomic = False
+ paths:
+ include:
+ - "**/migrations"
+ message: 'A batched migration should not be atomic. Add "atomic = False" to the Migration class'
+ languages: [python]
+ severity: ERROR