From 2cf19b79ac09f502a3bb72fab170e21bc9ed63c1 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 5 Oct 2016 18:57:35 +0530 Subject: [PATCH] Commit after locking and unlocking while queuing action --- frappe/model/document.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index ea1489b6c8..6b4bc96022 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -974,7 +974,6 @@ class Document(BaseDocument): def queue_action(self, action, **kwargs): '''Run an action in background. If the action has an inner function, like _submit for submit, it will call that instead''' - if action in ('save', 'submit', 'cancel'): # set docstatus explicitly again due to inconsistent action self.docstatus = {'save':0, 'submit':1, 'cancel': 2}[action] @@ -988,6 +987,7 @@ class Document(BaseDocument): action = '_' + action self.lock() + frappe.db.commit() enqueue('frappe.model.document.execute_action', doctype=self.doctype, name=self.name, action=action, **kwargs) @@ -995,9 +995,10 @@ def execute_action(doctype, name, action, **kwargs): '''Execute an action on a document (called by background worker)''' doc = frappe.get_doc(doctype, name) doc.unlock() + frappe.db.commit() try: getattr(doc, action)(**kwargs) - except frappe.ValidationError: + except Exception: # add a comment (?) if frappe.local.message_log: msg = json.loads(frappe.local.message_log[-1]).get('message') @@ -1005,11 +1006,4 @@ def execute_action(doctype, name, action, **kwargs): msg = '
' + frappe.get_traceback() + '
' doc.add_comment('Comment', _('Action Failed') + '

' + msg) - - doc.notify_update() - except Exception: - # add a comment (?) - doc.add_comment('Comment', - _('Action Failed') + '
' + frappe.get_traceback() + '
') - doc.notify_update()