Skip to content

Raise ValueError instead of KeyError when cancel_previous_runs=True and no job identifier is provided#62393

Merged
Lee-W merged 5 commits intoapache:mainfrom
SameerMesiah97:62392-Databricks-Cancel-PrevRuns-Fix
Mar 9, 2026
Merged

Raise ValueError instead of KeyError when cancel_previous_runs=True and no job identifier is provided#62393
Lee-W merged 5 commits intoapache:mainfrom
SameerMesiah97:62392-Databricks-Cancel-PrevRuns-Fix

Conversation

@SameerMesiah97
Copy link
Contributor

@SameerMesiah97 SameerMesiah97 commented Feb 24, 2026

Description

This change ensures that DatabricksRunNowOperator raises a clear ValueError when cancel_previous_runs=True is set without specifying either job_id or job_name. Previously, the operator failed with a raw KeyError at execution time.

The behavior remains unchanged for valid configurations. This update aligns the operator with existing validation patterns by surfacing configuration errors as ValueError rather than internal Python errors.

Rationale

DatabricksRunNowOperator already performs validation for conflicting and missing parameters using AirflowException. In this specific branch, however, an invalid configuration surfaced as a raw KeyError, which exposes internal implementation details and produces inconsistent error semantics.

Raising an ValueError provides clearer feedback to DAG authors and keeps validation behavior consistent across the operator.

Tests

A unit test has been added to verify that a ValueErroris raised whencancel_previous_runs=True` is used without a job identifier.

Backwards Compatibility

This change does not modify valid execution paths or operator semantics. It only replaces an unintended KeyError with a ValueError.

Closes: #62392

…s provided. Replace unsafe dictionary access in `DatabricksRunNowOperator.execute()` with a guarded lookup and raise a clear `AirflowException` if neither `job_id` nor `job_name` is available at execution time. Add unit test coveringthe failure case and ensuring no downstream hook methods are invoked.
@SameerMesiah97 SameerMesiah97 changed the title Raise AirflowException instead of KeyError when cancel_previous_runs=True and no job identifier is provided Raise ValueError instead of KeyError when cancel_previous_runs=True and no job identifier is provided Feb 24, 2026
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few nits. Overall looks good. But we'll need to update the description. once updated, I'll approve this PR. Thanks!

@SameerMesiah97
Copy link
Contributor Author

a few nits. Overall looks good. But we'll need to update the description. once updated, I'll approve this PR. Thanks!

Description updated.

SameerMesiah97 and others added 2 commits February 24, 2026 03:02
…s/databricks.py

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
…bricks.py

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
@SameerMesiah97
Copy link
Contributor Author

@Lee-W

Looks like the second commit (the one that added ‘call()’ to the test) broke CI. Do you still want to keep it?

@Lee-W
Copy link
Member

Lee-W commented Feb 24, 2026

@Lee-W

Looks like the second commit (the one that added ‘call()’ to the test) broke CI. Do you still want to keep it?

from unittest.mock import call

Copy link
Member

@guan404ming guan404ming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SameerMesiah97
Copy link
Contributor Author

@Lee-W @guan404ming

All comments have been resolved.

@Lee-W Lee-W merged commit 08424fe into apache:main Mar 9, 2026
90 checks passed
jason810496 pushed a commit to jason810496/airflow that referenced this pull request Mar 10, 2026
…nd no job identifier is provided (apache#62393)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Sameer Mesiah <smesiah971@gmail.com>
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
…nd no job identifier is provided (apache#62393)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Sameer Mesiah <smesiah971@gmail.com>
Pyasma pushed a commit to Pyasma/airflow that referenced this pull request Mar 13, 2026
…nd no job identifier is provided (apache#62393)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Sameer Mesiah <smesiah971@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabricksRunNowOperator raises KeyError when cancel_previous_runs=True and no job identifier is provided

4 participants