fix(prepared_report): handle missing attachments in get_prepared_data method (#38449)

This commit is contained in:
Saqib Ansari 2026-04-18 19:28:41 +05:30 committed by GitHub
parent 63b8d78075
commit 75bae453ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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):