Repository: frappe/frappe

Issue:
Clearing attachment from web form causes error on save.
## Description of the issue
When clearing an attachment from a web form, an error is returned and the attachment is not deleted from the file store.

## Context information (for bug reports)
erpnext 13.x.x-develop
frappe 13.x.x-develop


## Steps to reproduce the issue

1. create web form with attachment
2. add attachment and save
3. delete attachment and save

### Observed result
Error is returned, file is removed from document, but is still in filestore.

### Expected result
No error and the removed attachment is deleted from filestore.

### Stacktrace / full error message
 File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/website/doctype/web_form/web_form.py", line 460, in accept
    remove_file_by_url(doc.get(fieldname), doctype=doc.doctype, name=doc.name)
  File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 763, in remove_file_by_url
    fid = frappe.db.get_value("File", {
  File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 413, in get_value
    ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug,
  File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 458, in get_values
    out = self._get_values_from_table(fields, filters, doctype, as_dict, debug, order_by, update, for_update=for_update)
  File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 603, in _get_values_from_table
    r = self.sql("select {fields} from `tab{doctype}` {where} {conditions} {order_by} {for_update}"
  File "/home/ccampbell/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 147, in sql
    self._cursor.execute(query, values)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py", line 168, in execute
    query = self.mogrify(query, args)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py", line 147, in mogrify
    query = query % self._escape_args(args, conn)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py", line 127, in _escape_args
    return {key: conn.literal(val) for (key, val) in args.items()}
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py", line 127, in <dictcomp>
    return {key: conn.literal(val) for (key, val) in args.items()}
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py", line 467, in literal
    return self.escape(obj, self.encoders)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py", line 460, in escape
    return converters.escape_item(obj, self.charset, mapping=mapping)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/converters.py", line 25, in escape_item
    val = encoder(val, charset, mapping)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/converters.py", line 33, in escape_dict
    quoted = escape_item(v, charset, mapping)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/converters.py", line 27, in escape_item
    val = encoder(val, mapping)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/converters.py", line 118, in escape_unicode
    return u"'%s'" % _escape_unicode(value)
  File "/home/ccampbell/frappe/frappe-bench/env/lib/python3.8/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
TypeError: 'NoneType' object is not callable

## Additional information
Linux Mint



Discussion:

Resolving patch:
diff --git a/frappe/website/doctype/web_form/web_form.py b/frappe/website/doctype/web_form/web_form.py
--- a/frappe/website/doctype/web_form/web_form.py
+++ b/frappe/website/doctype/web_form/web_form.py
@@ -457,7 +457,7 @@ def accept(web_form, data, docname=None, for_payment=False):
 	if files_to_delete:
 		for f in files_to_delete:
 			if f:
-				remove_file_by_url(doc.get(fieldname), doctype=doc.doctype, name=doc.name)
+				remove_file_by_url(f, doctype=doc.doctype, name=doc.name)
 
 
 	frappe.flags.web_form_doc = doc


Test patch: