diff --git a/frappe/core/doctype/file_data/file_data.py b/frappe/core/doctype/file_data/file_data.py index a457a3da5b..4d88a6adca 100644 --- a/frappe/core/doctype/file_data/file_data.py +++ b/frappe/core/doctype/file_data/file_data.py @@ -44,8 +44,8 @@ class FileData(Document): pass # if file not attached to any other record, delete it - if self.file_name and not frappe.db.count("File Data", - {"content_hash": self.content_hash, "name": ["!=", self.name]}): + if self.file_name and self.content_hash and (not frappe.db.count("File Data", + {"content_hash": self.content_hash, "name": ["!=", self.name]})): delete_file_data_content(self) def on_rollback(self): diff --git a/frappe/patches/4_0/file_manager_hooks.py b/frappe/patches/4_0/file_manager_hooks.py index 5c72e62da3..ef043d4d31 100644 --- a/frappe/patches/4_0/file_manager_hooks.py +++ b/frappe/patches/4_0/file_manager_hooks.py @@ -21,7 +21,16 @@ def execute(): b.file_url = os.path.normpath('/' + old_file_name) else: b.file_url = os.path.normpath('/files/' + old_file_name) - _file_name, content = get_file(name) - b.content_hash = get_content_hash(content) - b.save() + try: + _file_name, content = get_file(name) + b.content_hash = get_content_hash(content) + except IOError: + print 'Warning: Error processing ', name + _file_name = old_file_name + b.content_hash = None + + try: + b.save() + except frappe.DuplicateEntryError: + frappe.delete_doc(b.doctype, b.name)