mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 23:52:57 +00:00
fix: dont fail repost for recoverable errors (#30979)
recoverable erros: 1. timeout 2. lock/deadlocks
This commit is contained in:
@@ -367,6 +367,7 @@ erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances
|
|||||||
erpnext.patches.v13_0.create_gst_custom_fields_in_quotation
|
erpnext.patches.v13_0.create_gst_custom_fields_in_quotation
|
||||||
erpnext.patches.v13_0.copy_custom_field_filters_to_website_item
|
erpnext.patches.v13_0.copy_custom_field_filters_to_website_item
|
||||||
erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype
|
erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype
|
||||||
|
erpnext.patches.v13_0.requeue_recoverable_reposts
|
||||||
erpnext.patches.v14_0.discount_accounting_separation
|
erpnext.patches.v14_0.discount_accounting_separation
|
||||||
erpnext.patches.v14_0.delete_employee_transfer_property_doctype
|
erpnext.patches.v14_0.delete_employee_transfer_property_doctype
|
||||||
erpnext.patches.v13_0.create_accounting_dimensions_in_orders
|
erpnext.patches.v13_0.create_accounting_dimensions_in_orders
|
||||||
|
|||||||
21
erpnext/patches/v13_0/requeue_recoverable_reposts.py
Normal file
21
erpnext/patches/v13_0/requeue_recoverable_reposts.py
Normal file
@@ -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
|
||||||
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.exceptions import QueryDeadlockError, QueryTimeoutError
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cint, get_link_to_form, get_weekday, now, nowtime
|
from frappe.utils import cint, get_link_to_form, get_weekday, now, nowtime
|
||||||
from frappe.utils.user import get_users_with_role
|
from frappe.utils.user import get_users_with_role
|
||||||
|
from rq.timeouts import JobTimeoutException
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.utils import get_future_stock_vouchers, repost_gle_for_stock_vouchers
|
from erpnext.accounts.utils import get_future_stock_vouchers, repost_gle_for_stock_vouchers
|
||||||
@@ -15,6 +17,8 @@ from erpnext.stock.stock_ledger import (
|
|||||||
repost_future_sle,
|
repost_future_sle,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
RecoverableErrors = (JobTimeoutException, QueryDeadlockError, QueryTimeoutError)
|
||||||
|
|
||||||
|
|
||||||
class RepostItemValuation(Document):
|
class RepostItemValuation(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
@@ -132,7 +136,7 @@ def repost(doc):
|
|||||||
|
|
||||||
doc.set_status("Completed")
|
doc.set_status("Completed")
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
traceback = frappe.get_traceback()
|
traceback = frappe.get_traceback()
|
||||||
doc.log_error("Unable to repost item valuation")
|
doc.log_error("Unable to repost item valuation")
|
||||||
@@ -142,9 +146,9 @@ def repost(doc):
|
|||||||
message += "<br>" + "Traceback: <br>" + traceback
|
message += "<br>" + "Traceback: <br>" + traceback
|
||||||
frappe.db.set_value(doc.doctype, doc.name, "error_log", message)
|
frappe.db.set_value(doc.doctype, doc.name, "error_log", message)
|
||||||
|
|
||||||
|
if not isinstance(e, RecoverableErrors):
|
||||||
notify_error_to_stock_managers(doc, message)
|
notify_error_to_stock_managers(doc, message)
|
||||||
doc.set_status("Failed")
|
doc.set_status("Failed")
|
||||||
raise
|
|
||||||
finally:
|
finally:
|
||||||
if not frappe.flags.in_test:
|
if not frappe.flags.in_test:
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user