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"