Skip to content

Add on_kill() to DatabricksTaskBaseOperator to cancel runs on task kill#69442

Open
victorymakes wants to merge 4 commits into
apache:mainfrom
victorymakes:fix/databricks-task-base-operator-on-kill
Open

Add on_kill() to DatabricksTaskBaseOperator to cancel runs on task kill#69442
victorymakes wants to merge 4 commits into
apache:mainfrom
victorymakes:fix/databricks-task-base-operator-on-kill

Conversation

@victorymakes

Copy link
Copy Markdown
Contributor

Summary

DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — is missing the same implementation, so Databricks jobs continue running after the Airflow task is killed, orphaning compute resources and incurring unnecessary cloud spend.

DatabricksWorkflowTaskGroup received on_kill() in #42115; this PR closes the remaining gap for standalone task operators.

Changes

  • Adds on_kill() to DatabricksTaskBaseOperator using self.databricks_run_id, which is:
    • initialised to None in __init__ (no AttributeError risk)
    • set by _launch_job() the moment the run is submitted — earlier than any polling or permission calls
  • Adds unit tests covering both the cancel and no-op paths

Testing

pytest providers/databricks/tests/unit/databricks/operators/test_databricks.py -k "on_kill"
Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement
on_kill() to cancel the Databricks run when an Airflow task is killed.
DatabricksTaskBaseOperator — used by DatabricksTaskOperator and
DatabricksNotebookOperator — is missing the same implementation, so
Databricks jobs continue running after the Airflow task is killed,
orphaning compute resources.

DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes
the remaining gap for standalone task operators.

Uses self.databricks_run_id which is initialised to None in __init__ and
set by _launch_job() the moment the run is submitted.
@eladkal eladkal requested a review from amoghrajesh July 6, 2026 15:45
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.

1 participant