Attachment with different file name show duplicate entry

hi have a html form with 3 attachment field

when i attach files my_file_1.txt, my_file_2.txt ,my_file_3.txt in 3 attachment attachment respectivly. I am getting Same file has already been attached to the record. to avoid that i wrote below code in validate_duplicate_entry function of doctype

n_records = frappe.db.sql(“”“select name from tabFile
where content_hash=%s
and name!=%s
and attached_to_doctype=%s
and attached_to_name=%s”“”, (self.content_hash,, self.attached_to_doctype,
if len(n_records) > 0:
self.duplicate_entry = n_records[0][0]
if self.attached_to_doctype != “MyDoctype”:
frappe.throw(frappe._(“Same file has already been attached to the record”), frappe.DuplicateEntryError)

what the code i added is this
if self.attached_to_doctype != "Student Applicant":

but when i submit the html form 3 attachments with same name on my doctype


oh i forget to mention that when this html form is submits data will be saved to myDoctype doctype

so i think that frappe i automatically detecting content of the file or something like that how can i buy pass that.

version of erpnext that i use is 7

i assume that you already fixed in v 10. but my curiosity to find how frappe identifying the content of file or similarity of file name forced me to put this question in here.

if any one who had already done some thing like this before pls share.


code for saving file is
filedoc = save_file(fd[“filename”], fd[“dataurl”],
“Student Applicant”,, decode=False, is_private=1)

Duplicate files are determined by the content_hash even if the titles are different. If you have 3 files with the same content, they are duplicate.

1 Like

@netchampfaris how can bypass that can you share the code which is checking hascode

is it at

It is the same code you pasted. Notice that it is querying the files which has the same content_hash

1 Like

@netchampfaris okey thanks i will remove this hash i will replay if it work or not

@netchampfaris faris i removed content hash from where clause and i get 2 files with same file name like above screen shot.