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 29, 2024
1 parent 6f64052 commit 0223f3a
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 @@ -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):
Expand Down

0 comments on commit 0223f3a

Please sign in to comment.