From 75bae453acd3bdd6f2476abefc8ec5cb9f33f88d Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Sat, 18 Apr 2026 19:28:41 +0530 Subject: [PATCH] fix(prepared_report): handle missing attachments in get_prepared_data method (#38449) --- .../prepared_report/prepared_report.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frappe/core/doctype/prepared_report/prepared_report.py b/frappe/core/doctype/prepared_report/prepared_report.py index 3aa9e4f0d5..54d8bfcbac 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.py +++ b/frappe/core/doctype/prepared_report/prepared_report.py @@ -87,18 +87,21 @@ class PreparedReport(Document): ) def get_prepared_data(self, with_file_name=False): - if attachments := get_attachments(self.doctype, self.name): - attachment = None - for f in attachments or []: - if f.file_url.endswith(".gz"): - attachment = f - break + attachments = get_attachments(self.doctype, self.name) + if not attachments: + frappe.throw(_("No attachment found for the prepared report"), title=_("Attachment Not Found")) - attached_file = frappe.get_doc("File", attachment.name) + attachment = None + for f in attachments or []: + if f.file_url.endswith(".gz"): + attachment = f + break - if with_file_name: - return (gzip.decompress(attached_file.get_content()), attachment.file_name) - return gzip.decompress(attached_file.get_content()) + attached_file = frappe.get_doc("File", attachment.name) + + if with_file_name: + return (gzip.decompress(attached_file.get_content()), attachment.file_name) + return gzip.decompress(attached_file.get_content()) def generate_report(prepared_report):