Skip to content

Commit d438670

Browse files
committedMar 6, 2018
parser: use Patch.objects.create instead of save()
Attempts to do parallel parsing with MySQL threw the following errors: _mysql_exceptions.OperationalError: (1213, 'Deadlock found when trying to get lock; try restarting transaction') Looking at the code, it was thrown when we created a patch like this: patch = Patch(...) patch.save() The SQL statements that were being generated were weird: UPDATE "patchwork_patch" SET ... INSERT INTO "patchwork_patch" (...) VALUES (...) As far as I can tell, the update could never work, because it was trying to update a patch that didn't exist yet. My hypothesis is that Django somehow didn't quite 'get' that because of the backend complexity of the Patch model, so it tried to do an update, failed, and then tried an insert. Change the code to use Patch.objects.create, which makes the UPDATEs and the weird MySQL errors go away. Also move it up a bit earlier in the process so that if things go wrong later at least we've committed the patch to the db. Reviewed-by: Andrew Donnellan <[email protected]> Reviewed-by: Stephen Finucane <[email protected]> Signed-off-by: Daniel Axtens <[email protected]>
·
v2.0.4v2.0.2
1 parent e11b716 commit d438670

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed
 

‎patchwork/parser.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,20 @@ def parse_mail(mail, list_id=None):
980980
filenames = find_filenames(diff)
981981
delegate = find_delegate_by_filename(project, filenames)
982982

983+
patch = Patch.objects.create(
984+
msgid=msgid,
985+
project=project,
986+
name=name[:255],
987+
date=date,
988+
headers=headers,
989+
submitter=author,
990+
content=message,
991+
diff=diff,
992+
pull_url=pull_url,
993+
delegate=delegate,
994+
state=find_state(mail))
995+
logger.debug('Patch saved')
996+
983997
# if we don't have a series marker, we will never have an existing
984998
# series to match against.
985999
series = None
@@ -1020,21 +1034,6 @@ def parse_mail(mail, list_id=None):
10201034
except SeriesReference.DoesNotExist:
10211035
SeriesReference.objects.create(series=series, msgid=ref)
10221036

1023-
patch = Patch(
1024-
msgid=msgid,
1025-
project=project,
1026-
name=name[:255],
1027-
date=date,
1028-
headers=headers,
1029-
submitter=author,
1030-
content=message,
1031-
diff=diff,
1032-
pull_url=pull_url,
1033-
delegate=delegate,
1034-
state=find_state(mail))
1035-
patch.save()
1036-
logger.debug('Patch saved')
1037-
10381037
# add to a series if we have found one, and we have a numbered
10391038
# patch. Don't add unnumbered patches (for example diffs sent
10401039
# in reply, or just messages with random refs/in-reply-tos)

0 commit comments

Comments
 (0)
Please sign in to comment.