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:
parent
acc27a147a
commit
deaa865fa8
1 changed files with 7 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue