From 2e577aa64e22d36bd2c643461eab7a76f77385b2 Mon Sep 17 00:00:00 2001 From: chillaranand Date: Thu, 14 Jul 2022 16:47:59 +0530 Subject: [PATCH] fix: Check for file url before validating remote file --- frappe/core/doctype/file/file.py | 2 +- frappe/core/doctype/file/test_file.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 7a66d45c73..e1faf331d6 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -262,7 +262,7 @@ class File(Document): def validate_remote_file(self): """Validates if file uploaded using URL already exist""" site_url = get_url() - if "/files/" in self.file_url and self.file_url.startswith(site_url): + if self.file_url and "/files/" in self.file_url and self.file_url.startswith(site_url): self.file_url = self.file_url.split(site_url, 1)[1] def set_folder_name(self): diff --git a/frappe/core/doctype/file/test_file.py b/frappe/core/doctype/file/test_file.py index a9d40b35b1..d849a2de4d 100644 --- a/frappe/core/doctype/file/test_file.py +++ b/frappe/core/doctype/file/test_file.py @@ -510,6 +510,16 @@ class TestFile(FrappeTestCase): ).insert(ignore_permissions=True) self.assertRaisesRegex(ValidationError, "not a zip file", test_file.unzip) + def test_create_file_without_file_url(self): + test_file = frappe.get_doc( + { + "doctype": "File", + "file_name": "logo", + "content": "frappe", + } + ).insert() + assert test_file is not None + class TestAttachment(unittest.TestCase): test_doctype = "Test For Attachment"