From b0af2daca46f442eebe49831fddc74c709cd60ee Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 15 Dec 2025 20:45:06 +0000 Subject: [PATCH] Improve error handling in _run_rota_job to persist logs and results for better UI diagnostics --- djangorota/rota/services.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/djangorota/rota/services.py b/djangorota/rota/services.py index 5f6e42b..f534d34 100644 --- a/djangorota/rota/services.py +++ b/djangorota/rota/services.py @@ -120,11 +120,36 @@ def _run_rota_job(run_id: int, use_external_generator: bool = False, generate_bu tb = traceback.format_exc() run.log = (run.log or "") + "\n" + tb result["builder_error"] = str(exc) + # Persist the log immediately so UI can show it even if + # the outer flow later marks the run failed. + try: + run.save(update_fields=["log"]) + except Exception: + pass run.mark_finished(result=result) except Exception: tb = traceback.format_exc() + # Ensure the traceback is persisted into the run log and result (if + # available) before marking the run failed so the UI can display the + # diagnostic information when viewing the run details. + try: + run.log = (run.log or "") + "\n" + tb + # If we have a partially constructed `result`, attach it so the + # failure page can show any captured stdout/stderr + try: + if 'result' in locals() and isinstance(result, dict): + run.result = result + run.save(update_fields=["log", "result"]) + else: + run.save(update_fields=["log"]) + except Exception: + # best-effort: ignore persistence errors here + pass + except Exception: + # ignore log assignment errors and continue to mark failed + pass try: run.mark_failed(message=tb) except Exception: