Skip to content

Commit 91dce3e

Browse files
jk-ozlabsstephenfin
authored andcommitted
parser: prevent IntegrityErrors
Currently, the parser relies on causing (and catching) IntegrityErrors on patch insert to catch duplicate (msgid,project) mails. This change performs an atomic select -> insert instead. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stephen Finucane <stephen@that.guru> [stephenfin: Remove 'expectedFailure' marker again] (cherry picked from commit 947c6aa)
1 parent 9463c2b commit 91dce3e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

patchwork/parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,10 @@ def parse_mail(mail, list_id=None):
10921092
filenames = find_filenames(diff)
10931093
delegate = find_delegate_by_filename(project, filenames)
10941094

1095-
try:
1095+
with transaction.atomic():
1096+
if Patch.objects.filter(project=project, msgid=msgid):
1097+
raise DuplicateMailError(msgid=msgid)
1098+
10961099
patch = Patch.objects.create(
10971100
msgid=msgid,
10981101
project=project,
@@ -1107,8 +1110,6 @@ def parse_mail(mail, list_id=None):
11071110
delegate=delegate,
11081111
state=find_state(mail))
11091112
logger.debug('Patch saved')
1110-
except IntegrityError:
1111-
raise DuplicateMailError(msgid=msgid)
11121113

11131114
for attempt in range(1, 11): # arbitrary retry count
11141115
try:

patchwork/tests/test_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,6 @@ def log_query_errors(execute, sql, params, many, context):
11611161

11621162
self.assertEqual(errors, [])
11631163

1164-
@unittest.expectedFailure
11651164
def test_duplicate_patch(self):
11661165
diff = read_patch('0001-add-line.patch')
11671166
m = create_email(diff, listid=self.listid, msgid='1@example.com')

0 commit comments

Comments
 (0)