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 Mar 9, 2026
Conversation
…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.
sjyangkevin
suggested changes
Feb 24, 2026
providers/databricks/src/airflow/providers/databricks/operators/databricks.py
Outdated
Show resolved
Hide resolved
Lee-W
requested changes
Feb 24, 2026
Lee-W
reviewed
Feb 24, 2026
Member
Lee-W
left a comment
There was a problem hiding this comment.
a few nits. Overall looks good. But we'll need to update the description. once updated, I'll approve this PR. Thanks!
providers/databricks/src/airflow/providers/databricks/operators/databricks.py
Outdated
Show resolved
Hide resolved
providers/databricks/tests/unit/databricks/operators/test_databricks.py
Outdated
Show resolved
Hide resolved
Contributor
Author
Description updated. |
…s/databricks.py Co-authored-by: Wei Lee <weilee.rx@gmail.com>
…bricks.py Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Lee-W
approved these changes
Feb 24, 2026
Contributor
Author
|
Looks like the second commit (the one that added ‘call()’ to the test) broke CI. Do you still want to keep it? |
Member
from unittest.mock import call |
Contributor
Author
|
All comments have been resolved. |
Lee-W
approved these changes
Mar 9, 2026
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>
81 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ensures that
DatabricksRunNowOperatorraises a clearValueErrorwhencancel_previous_runs=Trueis set without specifying eitherjob_idorjob_name. Previously, the operator failed with a rawKeyErrorat execution time.The behavior remains unchanged for valid configurations. This update aligns the operator with existing validation patterns by surfacing configuration errors as
ValueErrorrather than internal Python errors.Rationale
DatabricksRunNowOperatoralready performs validation for conflicting and missing parameters usingAirflowException. In this specific branch, however, an invalid configuration surfaced as a rawKeyError, which exposes internal implementation details and produces inconsistent error semantics.Raising an
ValueErrorprovides clearer feedback to DAG authors and keeps validation behavior consistent across the operator.Tests
A unit test has been added to verify that a ValueError
is 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
KeyErrorwith aValueError.Closes: #62392