From e4a11ca00d9975e55acc261c103d51d973377123 Mon Sep 17 00:00:00 2001 From: Dev-X25874 <283057883+Dev-X25874@users.noreply.github.com> Date: Sat, 23 May 2026 09:23:13 +0530 Subject: [PATCH 1/2] api_client: raise error when job run terminates with non-success result state --- dbt/adapters/databricks/api_client.py | 5 +++++ 1 file changed, 5 insertions(+) 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}") From bba823f55ddf046b7158ec1dc0e552794aa811bc Mon Sep 17 00:00:00 2001 From: Dev-X25874 <283057883+Dev-X25874@users.noreply.github.com> Date: Sat, 23 May 2026 09:24:14 +0530 Subject: [PATCH 2/2] tests/unit/api_client: add test for TERMINATED+FAILED poll_for_completion --- tests/unit/api_client/test_job_runs_api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)