From deaa865fa89f0cfcf835e77bc2bfe449a1c5ac01 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Tue, 10 Dec 2019 09:14:40 +0530 Subject: [PATCH] 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 --- .../v11_0/make_all_prepared_report_attachments_private.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frappe/patches/v11_0/make_all_prepared_report_attachments_private.py b/frappe/patches/v11_0/make_all_prepared_report_attachments_private.py index dd212d157e..f7b9e476a9 100644 --- a/frappe/patches/v11_0/make_all_prepared_report_attachments_private.py +++ b/frappe/patches/v11_0/make_all_prepared_report_attachments_private.py @@ -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 +