Skip to content

Commit

Permalink
Improve exception handling in get_execution_status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
QMalcolm committed Oct 30, 2024
1 parent fe24051 commit ec88729
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit ec88729

Please sign in to comment.