Fail DbtCloudHook.wait_for_job_run_status on ERROR or CANCELLED dbt Cloud job runs #61300
+35
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change updates
DbtCloudHook.wait_for_job_run_statusto raise an exception when a dbt Cloud job run reaches an unexpected terminal state (ERRORorCANCELLED), instead of returningFalse.The method now behaves as a safe synchronization primitive:
Truewhen the job run reaches an expected status.DbtCloudJobRunExceptionon terminal failure before the expected state.Rationale
wait_for_job_run_statusblocks until a job run completes and defaults to waiting forSUCCESS. Returning a boolean for terminal failure states is error-prone in an Airflow context, where task success and failure are exception-driven.The previous behavior allowed Airflow tasks to complete successfully even when the underlying dbt Cloud job failed, which is surprising given the method name, blocking behavior, and default expectations. Raising on unexpected terminal states aligns the method with Airflow execution semantics and prevents silent task success.
Notes
DbtCloudRunJobOperator.on_killnow treats cancellation confirmation as best-effort and guards against propagated exceptions to avoid masking task termination. Previously, this method relied on a boolean return value fromwait_for_job_run_statusto confirm cancellation. Sincewait_for_job_run_statuscan now raiseDbtCloudJobRunExceptionunder normal operation (for example, if the job reaches an unexpected terminal state or the confirmation times out), allowing those exceptions to propagate fromon_killcould incorrectly surface as task failures during shutdown.Tests
Updated unit tests for
wait_for_job_run_statusto assert exception-driven behavior on terminal job run failures.Documentation
The docstring for
wait_for_job_run_statushas been updated to explicitly document its exception-driven behavior, including the conditions under whichDbtCloudJobRunExceptionis raised.Backwards Compatibility
This change does not alter the public API or method signature, but it does change runtime behavior:
False.This behavior is consistent with Airflow’s exception-driven model and matches user expectations for a blocking “wait until complete” helper.
Closes: #61297