Merge pull request #2391 from mmoksh/fix-db-deadlock

Delete child table rows without causing database deadlock
This commit is contained in:
Nabin Hait 2016-11-30 12:07:22 +05:30 committed by GitHub
commit 8ce6717201

View file

@ -301,12 +301,16 @@ class Document(BaseDocument):
return
if rows:
# delete rows that do not match the ones in the
# document
frappe.db.sql("""delete from `tab{0}` where parent=%s
# select rows that do not match the ones in the document
deleted_rows = frappe.db.sql("""select name from `tab{0}` where parent=%s
and parenttype=%s and parentfield=%s
and name not in ({1})""".format(df.options, ','.join(['%s'] * len(rows))),
[self.name, self.doctype, fieldname] + rows)
if len(deleted_rows) > 0:
# delete rows that do not match the ones in the document
frappe.db.sql("""delete from `tab{0}` where name in ({1})""".format(df.options,
','.join(['%s'] * len(deleted_rows))), tuple(row[0] for row in deleted_rows))
else:
# no rows found, delete all rows
frappe.db.sql("""delete from `tab{0}` where parent=%s