From edf01ee1cd56147b5f57cf5345f943e82f258a1d Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 17 Nov 2022 14:43:03 +0530 Subject: [PATCH] fix(file): attached_to_name can be an integer (#18909) * fix(file): attached_to_name can be an integer incorrect validation introduces via https://github.com/frappe/frappe/pull/18880 * test(file): set correct fieldname * fix: check for str, int explicitly --- frappe/core/doctype/file/file.py | 4 ++-- frappe/core/doctype/file/test_file.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 0e28145c9a..0c21501589 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -101,8 +101,8 @@ class File(Document): if not self.attached_to_doctype: return - if self.attached_to_name and not isinstance(self.attached_to_name, str): - frappe.throw(_("Attached To Name must be a string"), TypeError) + if not self.attached_to_name or not isinstance(self.attached_to_name, (str, int)): + frappe.throw(_("Attached To Name must be a string or an integer"), frappe.ValidationError) if not self.attached_to_field: return diff --git a/frappe/core/doctype/file/test_file.py b/frappe/core/doctype/file/test_file.py index ed97c5683d..86bd69eb5f 100644 --- a/frappe/core/doctype/file/test_file.py +++ b/frappe/core/doctype/file/test_file.py @@ -85,7 +85,7 @@ class TestBase64File(FrappeTestCase): "doctype": "File", "file_name": "test_base64.txt", "attached_to_doctype": self.attached_to_doctype, - "attached_to_docname": self.attached_to_docname, + "attached_to_name": self.attached_to_docname, "content": self.test_content, "decode": True, }