diff --git a/dbt/adapters/databricks/api_client.py b/dbt/adapters/databricks/api_client.py index c36621079..105866eb7 100644 --- a/dbt/adapters/databricks/api_client.py +++ b/dbt/adapters/databricks/api_client.py @@ -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}") diff --git a/tests/unit/api_client/test_job_runs_api.py b/tests/unit/api_client/test_job_runs_api.py index 922fd7cfd..ac766b63f 100644 --- a/tests/unit/api_client/test_job_runs_api.py +++ b/tests/unit/api_client/test_job_runs_api.py @@ -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)