Unique fields and webforms

I’m trying to use a webform to allow anonymous users to create new documents of a particular doctype (e.g., applicants to an academic program). I would like to keep one field unique (email_address), but in case of a duplicate I’d like the submitted information to overwrite whatever is already there. Right now, it’s just throwing an error at my customers.

Is there any way to accomplish this?

Thanks in advance!

Inside validate function of python file you can do something like -

def validate(self):
	.
	.
	existing_doc = frappe.get_doc('DocType', {'unique_fieldname': 'value'})
	if existing_doc:
		frappe.delete_doc('DocType', existing_doc.name)

What it does is before saving a data, if it finds it already exist, then delete that and let the new data be saved without throwing a duplicate error. Haven’t tested the code, but hope you get the idea.