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
This commit is contained in:
Faris Ansari 2022-11-17 14:43:03 +05:30 committed by GitHub
parent f3c00c2bdc
commit edf01ee1cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

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

View file

@ -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,
}