From e1a0ca11f1add3121bb80922e201138024713cc8 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Tue, 29 Oct 2024 13:01:53 -0500 Subject: [PATCH] Improve exception handling in `get_execution_status` Previously in `get_execution_status` if a non `DbtRuntimeError` exception was raised, the finally would be entered, but the `status`/`message` would not be set, and thus a `status not defined` exception would get raised on attempting to return. Tangentially, there is another issue where somehow the `node_status` is becoming `None`. In all my playing with `get_execution_status` I found that trying to return an undefined variable in the `finally` caused an undefined variable exception. However, if in some python version, it instead just handed back `None`, then this fix should also solve that. --- core/dbt/task/run.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/dbt/task/run.py b/core/dbt/task/run.py index df6afdfa797..d9bb9fe2249 100644 --- a/core/dbt/task/run.py +++ b/core/dbt/task/run.py @@ -93,11 +93,16 @@ def get_execution_status(sql: str, adapter: BaseAdapter) -> Tuple[RunStatus, str response, _ = adapter.execute(sql, auto_begin=False, fetch=False) status = RunStatus.Success message = response._message + except (KeyboardInterrupt, SystemExit): + raise except DbtRuntimeError as exc: status = RunStatus.Error message = exc.msg - finally: - return status, message + except Exception as exc: + status = RunStatus.Error + message = str(exc) + + return (status, message) def track_model_run(index, num_nodes, run_model_result):