Skip to content

Commit 55aa9cd

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 <[email protected]> Reviewed-by: Stephen Finucane <[email protected]>
1 parent 947c6aa commit 55aa9cd

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
@@ -1254,16 +1254,16 @@ def parse_mail(mail, list_id=None):
12541254

12551255
author = get_or_create_author(mail, project)
12561256

1257-
try:
1257+
with transaction.atomic():
1258+
if Comment.objects.filter(submission=submission, msgid=msgid):
1259+
raise DuplicateMailError(msgid=msgid)
12581260
comment = Comment.objects.create(
12591261
submission=submission,
12601262
msgid=msgid,
12611263
date=date,
12621264
headers=headers,
12631265
submitter=author,
12641266
content=message)
1265-
except IntegrityError:
1266-
raise DuplicateMailError(msgid=msgid)
12671267

12681268
logger.debug('Comment saved')
12691269

patchwork/tests/test_parser.py

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

11471147
self.assertEqual(Patch.objects.count(), 1)
1148+
1149+
def test_duplicate_comment(self):
1150+
diff = read_patch('0001-add-line.patch')
1151+
m1 = create_email(diff, listid=self.listid, msgid='[email protected]')
1152+
_parse_mail(m1)
1153+
1154+
m2 = create_email('test', listid=self.listid, msgid='[email protected]',
1155+
in_reply_to='[email protected]')
1156+
self._test_duplicate_mail(m2)
1157+
1158+
self.assertEqual(Patch.objects.count(), 1)
1159+
self.assertEqual(Comment.objects.count(), 1)

0 commit comments

Comments
 (0)