From ec88729e63d23f27047555949ade985a440e3b65 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 e0c436b5a61..0900f06c06f 100644 --- a/core/dbt/task/run.py +++ b/core/dbt/task/run.py @@ -94,11 +94,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 _get_adapter_info(adapter, run_model_result) -> Dict[str, Any]: