Skip to content

Commit 69cd420

Browse files
jk-ozlabsstephenfin
authored andcommitted
parser: don't trigger database IntegrityErrors on duplicate comments
As we've done for the Patch model, this change prevents database errors from duplicate Comments. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Reviewed-by: Stephen Finucane <stephen@that.guru> (cherry picked from commit 55aa9cd)
1 parent 91dce3e commit 69cd420

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

patchwork/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,16 +1277,16 @@ def parse_mail(mail, list_id=None):
12771277

12781278
author = get_or_create_author(mail, project)
12791279

1280-
try:
1280+
with transaction.atomic():
1281+
if Comment.objects.filter(submission=submission, msgid=msgid):
1282+
raise DuplicateMailError(msgid=msgid)
12811283
comment = Comment.objects.create(
12821284
submission=submission,
12831285
msgid=msgid,
12841286
date=date,
12851287
headers=headers,
12861288
submitter=author,
12871289
content=message)
1288-
except IntegrityError:
1289-
raise DuplicateMailError(msgid=msgid)
12901290

12911291
logger.debug('Comment saved')
12921292

patchwork/tests/test_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,3 +1168,15 @@ def test_duplicate_patch(self):
11681168
self._test_duplicate_mail(m)
11691169

11701170
self.assertEqual(Patch.objects.count(), 1)
1171+
1172+
def test_duplicate_comment(self):
1173+
diff = read_patch('0001-add-line.patch')
1174+
m1 = create_email(diff, listid=self.listid, msgid='1@example.com')
1175+
_parse_mail(m1)
1176+
1177+
m2 = create_email('test', listid=self.listid, msgid='2@example.com',
1178+
in_reply_to='1@example.com')
1179+
self._test_duplicate_mail(m2)
1180+
1181+
self.assertEqual(Patch.objects.count(), 1)
1182+
self.assertEqual(Comment.objects.count(), 1)

0 commit comments

Comments
 (0)