After doing some major updates on ERPNext and MariaDB on our system, a problem appears with submitting Sales Invoices or Delivery Notes with grand total of zero and are linked back to parent Sales Order. (We have been using it for free give away promotions)
Stack trace as follow -
Traceback (most recent call last):
File “/home/naymin/frappe-bench/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/naymin/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/naymin/frappe-bench/apps/frappe/frappe/handler.py”, line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/naymin/frappe-bench/apps/frappe/frappe/init.py”, line 935, in call
return fn(*args, **newargs)
File “/home/naymin/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 778, in submit
self._submit()
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 767, in _submit
self.save()
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 256, in save
return self._save(*args, **kwargs)
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 307, in _save
self.run_post_save_methods()
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 831, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 702, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 965, in composer
return composed(self, method, *args, **kwargs)
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 948, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/naymin/frappe-bench/apps/frappe/frappe/model/document.py”, line 696, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/naymin/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 122, in on_submit
self.update_prevdoc_status()
File “/home/naymin/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py”, line 110, in update_prevdoc_status
self.update_qty()
File “/home/naymin/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py”, line 227, in update_qty
self._update_percent_field_in_targets(args, update_modified)
File “/home/naymin/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py”, line 272, in _update_percent_field_in_targets
self._update_percent_field(args, update_modified)
File “/home/naymin/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py”, line 287, in _update_percent_field
where name=‘%(name)s’“”" % args)
File “/home/naymin/frappe-bench/apps/frappe/frappe/database.py”, line 163, in sql
self._cursor.execute(query)
File “/home/naymin/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 250, in execute
self.errorhandler(self, exc, value)
File “/home/naymin/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 50, in defaulterrorhandler
raise errorvalue
OperationalError: (1365, ‘Division by 0’)
But the code seems fine and hasn’t changed much before I faced this error.
Further digging shows this probably has to do with Feb 2017 update of MariaDB. There is a change in default setting of mariadb that deals with division by 0. Original setting is to return NULL and the change in version 10.2.4. The particular setting is ERROR_FOR_DIVISION_BY_ZERO.
Disabling this setting would be a quick fix (or may be removing strict mode entirely) but does this call for code fix on ERPNext as well?