瀏覽代碼

Merge pull request #2151 from nabinhait/hotfix

Commit after locking and unlocking while queuing action
version-14
Nabin Hait 8 年之前
committed by GitHub
父節點
當前提交
11dcd26642
共有 1 個文件被更改,包括 3 次插入9 次删除
  1. +3
    -9
      frappe/model/document.py

+ 3
- 9
frappe/model/document.py 查看文件

@@ -974,7 +974,6 @@ class Document(BaseDocument):
def queue_action(self, action, **kwargs): def queue_action(self, action, **kwargs):
'''Run an action in background. If the action has an inner function, '''Run an action in background. If the action has an inner function,
like _submit for submit, it will call that instead''' like _submit for submit, it will call that instead'''

if action in ('save', 'submit', 'cancel'): if action in ('save', 'submit', 'cancel'):
# set docstatus explicitly again due to inconsistent action # set docstatus explicitly again due to inconsistent action
self.docstatus = {'save':0, 'submit':1, 'cancel': 2}[action] self.docstatus = {'save':0, 'submit':1, 'cancel': 2}[action]
@@ -988,6 +987,7 @@ class Document(BaseDocument):
action = '_' + action action = '_' + action


self.lock() self.lock()
frappe.db.commit()
enqueue('frappe.model.document.execute_action', doctype=self.doctype, name=self.name, enqueue('frappe.model.document.execute_action', doctype=self.doctype, name=self.name,
action=action, **kwargs) action=action, **kwargs)


@@ -995,9 +995,10 @@ def execute_action(doctype, name, action, **kwargs):
'''Execute an action on a document (called by background worker)''' '''Execute an action on a document (called by background worker)'''
doc = frappe.get_doc(doctype, name) doc = frappe.get_doc(doctype, name)
doc.unlock() doc.unlock()
frappe.db.commit()
try: try:
getattr(doc, action)(**kwargs) getattr(doc, action)(**kwargs)
except frappe.ValidationError:
except Exception:
# add a comment (?) # add a comment (?)
if frappe.local.message_log: if frappe.local.message_log:
msg = json.loads(frappe.local.message_log[-1]).get('message') msg = json.loads(frappe.local.message_log[-1]).get('message')
@@ -1005,11 +1006,4 @@ def execute_action(doctype, name, action, **kwargs):
msg = '<pre><code>' + frappe.get_traceback() + '</pre></code>' msg = '<pre><code>' + frappe.get_traceback() + '</pre></code>'
doc.add_comment('Comment', _('Action Failed') + '<br><br>' + msg) doc.add_comment('Comment', _('Action Failed') + '<br><br>' + msg)

doc.notify_update()
except Exception:
# add a comment (?)
doc.add_comment('Comment',
_('Action Failed') + '<pre><code>' + frappe.get_traceback() + '</pre></code>')

doc.notify_update() doc.notify_update()

Loading…
取消
儲存