fix: defer DocType exports until after save response

Defer standard **DocType** file export and controller generation until after the save response is sent.
This allows the client form to receive the updated document payload before dev-mode file writes trigger a web reload and prevents follow-up `TimestampMismatchError` on consecutive **DocType** saves without forcing a full page reload.
This commit is contained in:
barredterra 2026-04-03 16:20:38 +02:00
parent e39067bfcd
commit 5876c70f86

View file

@ -550,11 +550,20 @@ class DocType(Document):
and (frappe.conf.developer_mode or frappe.flags.allow_doctype_export)
)
if allow_doctype_export:
def export_doctype_files():
self.export_doc()
self.make_controller_template()
self.set_base_class_for_controller()
self.export_types_to_controller()
request = getattr(frappe.local, "request", None)
# Defer file writes until after the response so the client can sync the saved doc first.
if request and hasattr(request, "after_response"):
request.after_response.add(export_doctype_files)
else:
export_doctype_files()
# update index
if not self.custom:
self.run_module_method("on_doctype_update")