Skip to content

Commit

Permalink
fix: dont fail repost for recoverable errors (#30979)
Browse files Browse the repository at this point in the history
recoverable erros:
1. timeout
2. lock/deadlocks

(cherry picked from commit 80d959c)

# Conflicts:
#	erpnext/patches.txt
  • Loading branch information
ankush authored and mergify[bot] committed May 16, 2022
1 parent e2028a0 commit 3c8a19a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,15 @@ erpnext.patches.v13_0.enable_ksa_vat_docs #1
erpnext.patches.v13_0.create_gst_custom_fields_in_quotation
erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances
erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype
<<<<<<< HEAD
erpnext.patches.v13_0.set_return_against_in_pos_invoice_references
erpnext.patches.v13_0.copy_custom_field_filters_to_website_item
erpnext.patches.v13_0.set_available_for_use_date_if_missing
erpnext.patches.v13_0.education_deprecation_warning
=======
erpnext.patches.v13_0.requeue_recoverable_reposts
erpnext.patches.v14_0.discount_accounting_separation
erpnext.patches.v14_0.delete_employee_transfer_property_doctype
>>>>>>> 80d959c579 (fix: dont fail repost for recoverable errors (#30979))
erpnext.patches.v13_0.create_accounting_dimensions_in_orders
erpnext.patches.v13_0.set_per_billed_in_return_delivery_note
21 changes: 21 additions & 0 deletions erpnext/patches/v13_0/requeue_recoverable_reposts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import frappe


def execute():
recoverable = ("QueryDeadlockError", "QueryTimeoutError", "JobTimeoutException")

failed_reposts = frappe.get_all(
"Repost Item Valuation",
fields=["name", "error_log"],
filters={
"status": "Failed",
"docstatus": 1,
"modified": (">", "2022-04-20"),
"error_log": ("is", "set"),
},
)
for riv in failed_reposts:
for exc in recoverable:
if exc in riv.error_log:
frappe.db.set_value("Repost Item Valuation", riv.name, "status", "Queued")
break
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import frappe
from frappe import _
from frappe.exceptions import QueryDeadlockError, QueryTimeoutError
from frappe.model.document import Document
from frappe.utils import cint, get_link_to_form, get_weekday, now, nowtime
from frappe.utils.user import get_users_with_role
from rq.timeouts import JobTimeoutException

import erpnext
from erpnext.accounts.utils import get_future_stock_vouchers, repost_gle_for_stock_vouchers
Expand All @@ -15,6 +17,8 @@
repost_future_sle,
)

RecoverableErrors = (JobTimeoutException, QueryDeadlockError, QueryTimeoutError)


class RepostItemValuation(Document):
def validate(self):
Expand Down Expand Up @@ -132,7 +136,7 @@ def repost(doc):

doc.set_status("Completed")

except Exception:
except Exception as e:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(traceback)
Expand All @@ -142,9 +146,9 @@ def repost(doc):
message += "<br>" + "Traceback: <br>" + traceback
frappe.db.set_value(doc.doctype, doc.name, "error_log", message)

notify_error_to_stock_managers(doc, message)
doc.set_status("Failed")
raise
if not isinstance(e, RecoverableErrors):
notify_error_to_stock_managers(doc, message)
doc.set_status("Failed")
finally:
if not frappe.flags.in_test:
frappe.db.commit()
Expand Down

0 comments on commit 3c8a19a

Please sign in to comment.