Skip to content

Commit 947c6aa

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 <[email protected]> Signed-off-by: Stephen Finucane <[email protected]> [stephenfin: Remove 'expectedFailure' marker again]
1 parent a60e75e commit 947c6aa

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
@@ -1069,7 +1069,10 @@ def parse_mail(mail, list_id=None):
10691069
filenames = find_filenames(diff)
10701070
delegate = find_delegate_by_filename(project, filenames)
10711071

1072-
try:
1072+
with transaction.atomic():
1073+
if Patch.objects.filter(project=project, msgid=msgid):
1074+
raise DuplicateMailError(msgid=msgid)
1075+
10731076
patch = Patch.objects.create(
10741077
msgid=msgid,
10751078
project=project,
@@ -1084,8 +1087,6 @@ def parse_mail(mail, list_id=None):
10841087
delegate=delegate,
10851088
state=find_state(mail))
10861089
logger.debug('Patch saved')
1087-
except IntegrityError:
1088-
raise DuplicateMailError(msgid=msgid)
10891090

10901091
for attempt in range(1, 11): # arbitrary retry count
10911092
try:

patchwork/tests/test_parser.py

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

11391139
self.assertEqual(errors, [])
11401140

1141-
@unittest.expectedFailure
11421141
def test_duplicate_patch(self):
11431142
diff = read_patch('0001-add-line.patch')
11441143
m = create_email(diff, listid=self.listid, msgid='[email protected]')

0 commit comments

Comments
 (0)