fix(patch): auto commit on more than 10000 writes

fixes issue where patch fails with:

frappe.exceptions.ValidationError: Too many writes in one request. Please send smaller requests

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai 2019-12-10 09:14:40 +05:30
parent acc27a147a
commit deaa865fa8
No known key found for this signature in database
GPG key ID: 75507BE256F40CED

View file

@ -3,6 +3,9 @@ import frappe
def execute():
if frappe.db.count("File", filters={"attached_to_doctype": "Prepared Report", "is_private": 0}) > 10000:
frappe.db.auto_commit_on_many_writes = True
files = frappe.get_all("File", fields=["name", "attached_to_name"], filters={"attached_to_doctype": "Prepared Report", "is_private": 0})
for file_dict in files:
# For some reason Prepared Report doc might not exist, check if it exists first
@ -17,3 +20,7 @@ def execute():
else:
# If Prepared Report doc doesn't exist then the file doc is useless. Delete it.
frappe.delete_doc("File", file_dict.name)
if frappe.db.auto_commit_on_many_writes:
frappe.db.auto_commit_on_many_writes = False