Merge pull request #19024 from ankush/sess_commit

refactor: request DB transaction
This commit is contained in:
mergify[bot] 2022-11-28 06:46:13 +00:00 committed by GitHub
commit e35c7a2a3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,7 @@ def application(request: Request):
rollback = after_request(rollback)
finally:
if request.method in ("POST", "PUT") and frappe.db and rollback:
if request.method in UNSAFE_HTTP_METHODS and frappe.db and rollback:
frappe.db.rollback()
frappe.rate_limiter.update()
@ -320,12 +320,16 @@ def handle_exception(e):
def after_request(rollback):
# if HTTP method would change server state, commit if necessary
if frappe.db and (
frappe.local.flags.commit or frappe.local.request.method in UNSAFE_HTTP_METHODS
if (
frappe.db
and (frappe.local.flags.commit or frappe.local.request.method in UNSAFE_HTTP_METHODS)
and frappe.db.transaction_writes
):
if frappe.db.transaction_writes:
frappe.db.commit()
rollback = False
frappe.db.commit()
rollback = False
elif frappe.db:
frappe.db.rollback()
rollback = False
# update session
if getattr(frappe.local, "session_obj", None):