Skip to content

Commit 55fb26b

Browse files
jk-ozlabsstephenfin
authored andcommitted
parser: don't trigger database IntegrityErrors on duplicate coverletters
As we've done for the Patch and Comment models, this change prevents database errors from duplicate CoverLetters. Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: Stephen Finucane <[email protected]> [stephenfin: Add release note]
1 parent 55aa9cd commit 55fb26b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

patchwork/parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,10 @@ def parse_mail(mail, list_id=None):
12271227
SeriesReference.objects.create(
12281228
msgid=msgid, project=project, series=series)
12291229

1230-
try:
1230+
with transaction.atomic():
1231+
if CoverLetter.objects.filter(project=project, msgid=msgid):
1232+
raise DuplicateMailError(msgid=msgid)
1233+
12311234
cover_letter = CoverLetter.objects.create(
12321235
msgid=msgid,
12331236
project=project,
@@ -1236,8 +1239,6 @@ def parse_mail(mail, list_id=None):
12361239
headers=headers,
12371240
submitter=author,
12381241
content=message)
1239-
except IntegrityError:
1240-
raise DuplicateMailError(msgid=msgid)
12411242

12421243
logger.debug('Cover letter saved')
12431244

patchwork/tests/test_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from patchwork.models import Patch
2222
from patchwork.models import Person
2323
from patchwork.models import State
24+
from patchwork.models import CoverLetter
2425
from patchwork.parser import clean_subject
2526
from patchwork.parser import get_or_create_author
2627
from patchwork.parser import find_patch_content as find_content
@@ -1157,3 +1158,12 @@ def test_duplicate_comment(self):
11571158

11581159
self.assertEqual(Patch.objects.count(), 1)
11591160
self.assertEqual(Comment.objects.count(), 1)
1161+
1162+
def test_duplicate_coverletter(self):
1163+
m = create_email('test', listid=self.listid, msgid='[email protected]')
1164+
del m['Subject']
1165+
m['Subject'] = '[PATCH 0/1] test cover letter'
1166+
1167+
self._test_duplicate_mail(m)
1168+
1169+
self.assertEqual(CoverLetter.objects.count(), 1)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
The parser module now uses an atomic select-insert when creating new patch,
5+
cover letter and comment entries. This prevents the integrity errors from
6+
being logged in the DB logs.
7+
(`#358 <https://github.com/getpatchwork/patchwork/issues/358>`__)

0 commit comments

Comments
 (0)