From d9a8b7ee78760359f12da45f906693ba6de0b294 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Fri, 13 Oct 2023 10:20:03 +0530 Subject: [PATCH] chore: rename __temporary_name & check temp_doc_name * renamed file_relink_temp_docname to __temporary_name * added check for temp_doc_name in relink_files in case someone calls the function it directly --- frappe/core/doctype/file/utils.py | 6 ++++-- frappe/desk/form/save.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/file/utils.py b/frappe/core/doctype/file/utils.py index 56c7dfd33f..d2e2b99a91 100644 --- a/frappe/core/doctype/file/utils.py +++ b/frappe/core/doctype/file/utils.py @@ -359,6 +359,8 @@ def attach_files_to_document(doc: "Document", event) -> None: def relink_files(doc, fieldname, temp_doc_name): + if not temp_doc_name: + return from frappe.utils.data import add_to_date, now_datetime """ @@ -391,12 +393,12 @@ def relink_files(doc, fieldname, temp_doc_name): def relink_mismatched_files(doc: "Document") -> None: - if not doc.get("file_relink_temp_docname", None): + if not doc.get("__temporary_name", None): return attach_fields = doc.meta.get("fields", {"fieldtype": ["in", ["Attach", "Attach Image"]]}) for df in attach_fields: if doc.get(df.fieldname): - relink_files(doc, df.fieldname, doc.file_relink_temp_docname) + relink_files(doc, df.fieldname, doc.__temporary_name) def decode_file_content(content: bytes) -> bytes: diff --git a/frappe/desk/form/save.py b/frappe/desk/form/save.py index 97dad8503d..e3ef2ba70b 100644 --- a/frappe/desk/form/save.py +++ b/frappe/desk/form/save.py @@ -20,7 +20,8 @@ def savedocs(doc, action): if doc.doctype not in ["DocType", "File"] and doc.name.startswith( "new-" + doc.doctype.lower().replace(" ", "-") ): - doc.file_relink_temp_docname = doc.name + # required to relink missing attachments if they exist. + doc.__temporary_name = doc.name set_local_name(doc) # action