On Cancel: Did not cancel

Dear all,

I have the following strange behaviour in a v12.1.16 environment: on a custom, submittable doctype, when “Cancel” is pressed, the error “Did not cancel” appears with the following trace:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 60, in application
	response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
	return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
	data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
	return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1036, in call
	return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 42, in cancel
	doc.cancel()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 862, in cancel
	self._cancel()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 852, in _cancel
	self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 271, in save
	return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 301, in _save
	self.check_if_latest()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 649, in check_if_latest
	self.check_docstatus_transition(tmp.docstatus)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 678, in check_docstatus_transition
	raise frappe.DocstatusTransitionError(_("Cannot change docstatus from 0 to 2"))
frappe.exceptions.DocstatusTransitionError: Cannot change docstatus from 0 to 2

However, F5 and the document is back to “Draft” status… Has anyone observed the same behaviour? Is this a new setting?

Note: when I click F5 on the submitted document, it turns to Draft again. The submitted status is shown on the form, but not stored in the database…

Got it (not sure if this is as it should be):

in my custom submit function, I needed to add self.save():

def submit(self):
    # do submit stuff
    self.save()
    return

Then it works…