Skip to content

Commit 0c74c92

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 <jk@ozlabs.org> Signed-off-by: Stephen Finucane <stephen@that.guru> [stephenfin: Add release note] (cherry picked from commit 55fb26b)
1 parent 69cd420 commit 0c74c92

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
@@ -1250,7 +1250,10 @@ def parse_mail(mail, list_id=None):
12501250
SeriesReference.objects.create(
12511251
msgid=msgid, project=project, series=series)
12521252

1253-
try:
1253+
with transaction.atomic():
1254+
if CoverLetter.objects.filter(project=project, msgid=msgid):
1255+
raise DuplicateMailError(msgid=msgid)
1256+
12541257
cover_letter = CoverLetter.objects.create(
12551258
msgid=msgid,
12561259
project=project,
@@ -1259,8 +1262,6 @@ def parse_mail(mail, list_id=None):
12591262
headers=headers,
12601263
submitter=author,
12611264
content=message)
1262-
except IntegrityError:
1263-
raise DuplicateMailError(msgid=msgid)
12641265

12651266
logger.debug('Cover letter saved')
12661267

patchwork/tests/test_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from patchwork.models import Patch
2424
from patchwork.models import Person
2525
from patchwork.models import State
26+
from patchwork.models import CoverLetter
2627
from patchwork.parser import clean_subject
2728
from patchwork.parser import get_or_create_author
2829
from patchwork.parser import find_patch_content as find_content
@@ -1180,3 +1181,12 @@ def test_duplicate_comment(self):
11801181

11811182
self.assertEqual(Patch.objects.count(), 1)
11821183
self.assertEqual(Comment.objects.count(), 1)
1184+
1185+
def test_duplicate_coverletter(self):
1186+
m = create_email('test', listid=self.listid, msgid='1@example.com')
1187+
del m['Subject']
1188+
m['Subject'] = '[PATCH 0/1] test cover letter'
1189+
1190+
self._test_duplicate_mail(m)
1191+
1192+
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)