]> git.ipfire.org Git - thirdparty/patchwork.git/commit
parser: use Patch.objects.create instead of save()
authorDaniel Axtens <dja@axtens.net>
Sun, 18 Feb 2018 01:57:03 +0000 (12:57 +1100)
committerDaniel Axtens <daniel.axtens@canonical.com>
Tue, 6 Mar 2018 14:32:42 +0000 (01:32 +1100)
commitd438670d38ce464d6211ba79ed10616e15c709fb
tree3a0c0f433ab2b33564319e2324b24ddaddc0b18d
parente11b7165025fbd38d473d40133bba9a038d293cf
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 <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/parser.py