refactor: exception propogation
diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.json b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.json
index 6e057ac..8291a4f 100644
--- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.json
+++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.json
@@ -10,6 +10,7 @@
"column_break_txbg",
"status",
"tasks_section",
+ "error_log",
"delete_bin_data",
"delete_leads_and_addresses",
"reset_company_default_values",
@@ -122,12 +123,18 @@
"label": "Initialize Summary Table",
"no_copy": 1,
"read_only": 1
+ },
+ {
+ "depends_on": "eval: doc.error_log",
+ "fieldname": "error_log",
+ "fieldtype": "Long Text",
+ "label": "Error Log"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2024-02-05 10:36:34.229864",
+ "modified": "2024-03-19 17:04:49.369734",
"modified_by": "Administrator",
"module": "Setup",
"name": "Transaction Deletion Record",
diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
index 039d9a5..b1e7511 100644
--- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
+++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
@@ -35,6 +35,7 @@
delete_transactions: DF.Check
doctypes: DF.Table[TransactionDeletionRecordDetails]
doctypes_to_be_ignored: DF.Table[TransactionDeletionRecordItem]
+ error_log: DF.LongText | None
initialize_doctypes_table: DF.Check
reset_company_default_values: DF.Check
status: DF.Literal["Queued", "Running", "Failed", "Completed", "Cancelled"]
@@ -146,11 +147,21 @@
task_to_execute=task,
)
+ # todo: add a non-background job based approach as well
+
def execute_task(self, task_to_execute: str | None = None):
if task_to_execute:
method = self.task_to_internal_method_map[task_to_execute]
if task := getattr(self, method, None):
- task()
+ try:
+ task()
+ except Exception as err:
+ frappe.db.rollback()
+ traceback = frappe.get_traceback(with_context=True)
+ if traceback:
+ message = "Traceback: <br>" + traceback
+ frappe.db.set_value(self.doctype, self.name, "error_log", message)
+ frappe.db.set_value(self.doctype, self.name, "status", "Failed")
def delete_notifications(self):
self.validate_doc_status()