Browse Source

fix: commit after processing request of "unsafe" http method

ref: https://developer.mozilla.org/en-US/docs/Glossary/safe
version-14
Gavin D'souza 3 years ago
parent
commit
56d97da32e
1 changed files with 6 additions and 1 deletions
  1. +6
    -1
      frappe/app.py

+ 6
- 1
frappe/app.py View File

@@ -30,6 +30,8 @@ local_manager = LocalManager([frappe.local])

_site = None
_sites_path = os.environ.get("SITES_PATH", ".")
SAFE_HTTP_METHODS = ("GET", "HEAD", "OPTIONS")
UNSAFE_HTTP_METHODS = ("POST", "PUT", "DELETE", "PATCH")


class RequestContext(object):
@@ -292,7 +294,10 @@ def handle_exception(e):


def after_request(rollback):
if (frappe.local.request.method in ("POST", "PUT") or frappe.local.flags.commit) and frappe.db:
# 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.transaction_writes:
frappe.db.commit()
rollback = False


Loading…
Cancel
Save