Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dbt/adapters/databricks/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ def _handle_terminal_state(self, run: Run) -> None:
self._handle_non_terminated_failure(
run, life_cycle_state, state_message, result_state or ""
)
elif result_state not in (None, "SUCCESS", "SUCCESS_WITH_FAILURES"):
raise DbtRuntimeError(
f"Python model run ended in result_state {result_state}"
f" (run_id: {run.run_id})\nState message: {state_message}"
)

def cancel(self, run_id: str) -> None:
logger.debug(f"Cancelling run id {run_id}")
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/api_client/test_job_runs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,20 @@ def test_poll_for_completion__success(self, _, api, workspace_client):
api.poll_for_completion("123")

workspace_client.jobs.get_run.assert_called_with(run_id=123)

@freezegun.freeze_time("2020-01-01")
@patch("time.sleep")
def test_poll_for_completion__failed(self, _, api, workspace_client):
mock_run = Mock(spec=Run)
mock_state = Mock(spec=RunState)
mock_state.life_cycle_state = RunLifeCycleState.TERMINATED
mock_state.result_state = RunResultState.FAILED
mock_state.state_message = "notebook raised exception"
mock_run.state = mock_state
mock_run.run_id = 123
workspace_client.jobs.get_run.return_value = mock_run

with pytest.raises(DbtRuntimeError) as exc:
api.poll_for_completion("123")

assert "Python model run ended in result_state FAILED" in str(exc.value)