Cannot Submit documents

Hi,
When I am trying to submit a document I am getting the following error:

Traceback (most recent call last):
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 831, in submit
self._submit()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 820, in _submit
self.save()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 256, in save
return self._save(*args, **kwargs)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 307, in _save
self.run_post_save_methods()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 890, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 1029, in composer
return composed(self, method, *args, **kwargs)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 1012, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 749, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/erp_healthcare/frappe-bench/apps/erpnext/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py”, line 128, in on_submit
self.update_stock_ledger()
File “/home/erp_healthcare/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py”, line 387, in update_stock_ledger
via_landed_cost_voucher=via_landed_cost_voucher)
File “/home/erp_healthcare/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 265, in make_sl_entries
make_sl_entries(sl_entries, is_amended, allow_negative_stock, via_landed_cost_voucher)
File “/home/erp_healthcare/frappe-bench/apps/erpnext/erpnext/stock/stock_ledger.py”, line 33, in make_sl_entries
sle_id = make_entry(sle, allow_negative_stock, via_landed_cost_voucher)
File “/home/erp_healthcare/frappe-bench/apps/erpnext/erpnext/stock/stock_ledger.py”, line 57, in make_entry
sle.insert()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/document.py”, line 230, in insert
self.db_insert()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 303, in db_insert
), list(d.values()))
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/database.py”, line 173, in sql
self._cursor.execute(query, values)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 163, in execute
query = self.mogrify(query, args)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 142, in mogrify
query = query % self._escape_args(args, conn)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 117, in _escape_args
return tuple(conn.literal(arg) for arg in args)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 117, in
return tuple(conn.literal(arg) for arg in args)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 819, in literal
return self.escape(obj, self.encoders)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 812, in escape
return converters.escape_item(obj, self.charset, mapping=mapping)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/converters.py”, line 27, in escape_item
val = encoder(val, mapping)
File “/home/erp_healthcare/frappe-bench/env/lib/python3.5/site-packages/pymysql/converters.py”, line 114, in escape_bytes
return “‘%s’” % value.decode(‘latin1’).translate(_escape_bytes_table)
AttributeError: ‘datetime.timedelta’ object has no attribute ‘decode’

How do I resolve it?

-Amit

@achillesrasquinha It may be due to Python 3. The code where it is bombing in PyMySQL is python 3 specific code.
-Amit

Yes, this is most likely true. Thanks for pointing it out! Send in a fix if you’re able to. :smile: Could you make an issue on GitHub and have it assigned to me?

I will not like to touch a core file. Best left to the experts of the platform. I will file a bug for you to be squashed.

PR https://github.com/frappe/frappe/issues/5196

1 Like