瀏覽代碼

Merge pull request #1036 from anandpdoshi/anand-feb-27

Better message for lock wait timeout and deadlock
version-14
Pratik Vyas 10 年之前
父節點
當前提交
fd20a1f7ba
共有 3 個文件被更改,包括 15 次插入1 次删除
  1. +9
    -0
      frappe/app.py
  2. +3
    -1
      frappe/model/rename_doc.py
  3. +3
    -0
      frappe/public/js/frappe/request.js

+ 9
- 0
frappe/app.py 查看文件

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import sys, os import sys, os
import json import json
import logging import logging
import MySQLdb


from werkzeug.wrappers import Request, Response from werkzeug.wrappers import Request, Response
from werkzeug.local import LocalManager from werkzeug.local import LocalManager
@@ -70,6 +71,14 @@ def application(request):
except Exception, e: except Exception, e:
http_status_code = getattr(e, "http_status_code", 500) http_status_code = getattr(e, "http_status_code", 500)


if (http_status_code==500
and isinstance(e, MySQLdb.OperationalError)
and e.args[0] in (1205, 1213)):
# 1205 = lock wait timeout
# 1213 = deadlock
# code 409 represents conflict
http_status_code = 409

if frappe.local.is_ajax: if frappe.local.is_ajax:
response = frappe.utils.response.report_error(http_status_code) response = frappe.utils.response.report_error(http_status_code)
else: else:


+ 3
- 1
frappe/model/rename_doc.py 查看文件

@@ -82,7 +82,9 @@ def rename_parent_and_child(doctype, old, new, meta):
update_child_docs(old, new, meta) update_child_docs(old, new, meta)


def validate_rename(doctype, new, meta, merge, force, ignore_permissions): def validate_rename(doctype, new, meta, merge, force, ignore_permissions):
exists = frappe.db.get_value(doctype, new)
# using for update so that it gets locked and someone else cannot edit it while this rename is going on!
exists = frappe.db.sql("select name from `tab{doctype}` where name=%s for update".format(doctype=doctype), new)
exists = exists[0][0] if exists else None


if merge and not exists: if merge and not exists:
frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(doctype, new), raise_exception=1) frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(doctype, new), raise_exception=1)


+ 3
- 0
frappe/public/js/frappe/request.js 查看文件

@@ -66,6 +66,9 @@ frappe.request.call = function(opts) {


msgprint(__("Not permitted")); msgprint(__("Not permitted"));
}, },
409: function(xhr) {
msgprint(__("Another transaction is blocking this one. Please try again in a few seconds."));
},
417: function(data, xhr) { 417: function(data, xhr) {
if(typeof data === "string") data = JSON.parse(data); if(typeof data === "string") data = JSON.parse(data);
opts.error_callback && opts.error_callback(data, xhr.responseText); opts.error_callback && opts.error_callback(data, xhr.responseText);


Loading…
取消
儲存