Skip to content

Commit 644cef7

Browse files
rjarrystephenfin
authored andcommitted
parsemail: wrap parse_mail() in a single transaction
Wrap the entire parse_mail() call in transaction.atomic() so that all database writes from email parsing run inside a single transaction. The existing transaction.atomic() blocks inside parse_mail() become savepoints within this outer transaction. The series deduplication retry logic continues to work since savepoint rollbacks are scoped to their own savepoint. This also ensures that any on_commit() callbacks registered by signal handlers only fire after the full email has been parsed and all patch/series associations are committed. Signed-off-by: Robin Jarry <robin@jarry.cc> Signed-off-by: Stephen Finucane <stephen@that.guru> Reviewed-by: Stephen Finucane <stephen@that.guru> [stephenfin: Slight tweaks to the release notes]
1 parent 3558907 commit 644cef7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

patchwork/management/commands/parsemail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99

1010
from django.core.management import base
11+
from django.db import transaction
1112

1213
from patchwork.parser import parse_mail
1314
from patchwork.parser import DuplicateMailError
@@ -57,7 +58,8 @@ def handle(self, *args, **options):
5758
# broken email (ValueError): 1 (this could be noisy, if it's an issue
5859
# we could use a different return code)
5960
try:
60-
result = parse_mail(mail, options['list_id'])
61+
with transaction.atomic():
62+
result = parse_mail(mail, options['list_id'])
6163
if result is None:
6264
logger.warning('Nothing added to database')
6365
except DuplicateMailError as exc:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Wrap the entire ``parse_mail()`` function in a single database
5+
transaction to prevent partial state from being visible to
6+
concurrent readers.

0 commit comments

Comments
 (0)