Skip to content

Add DatabricksDeleteJobsOperator to Databricks provider#64766

Open
ha2hi wants to merge 3 commits intoapache:mainfrom
ha2hi:add-databricks-delete-job
Open

Add DatabricksDeleteJobsOperator to Databricks provider#64766
ha2hi wants to merge 3 commits intoapache:mainfrom
ha2hi:add-databricks-delete-job

Conversation

@ha2hi
Copy link
Copy Markdown
Contributor

@ha2hi ha2hi commented Apr 6, 2026

Description

Currently, the Databricks provider lacks an operator to delete an existing Databricks job, although the Databricks REST API supports this functionality.

This PR introduces the DatabricksDeleteJobsOperator to fill this gap.

Changes made:

  1. DatabricksHook: Added a delete_job(self, job_id: int) method to interact with the api/2.2/jobs/delete endpoint.
  2. DatabricksDeleteJobsOperator: Created the operator using the updated hook.
  3. Unit Tests: Added comprehensive unit tests in test_databricks.py to verify the operator's execution, correct hook initialization with retry arguments, and template fields.

@ha2hi ha2hi changed the title Add DatabricksDeleteJobOperator to Databricks provider Add DatabricksDeleteJobsOperator to Databricks provider Apr 6, 2026
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 6, 2026

@ha2hi This PR has a few issues that need to be addressed before it can be reviewed — please see our Pull Request quality criteria.

Issues found:

  • Pre-commit / static checks: Failing: CI image checks / Static checks. Run prek run --from-ref main locally to find and fix issues. See Pre-commit / static checks docs.

Note: Your branch is 69 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.

@ha2hi ha2hi force-pushed the add-databricks-delete-job branch from 92267b9 to 9d8fc5e Compare April 8, 2026 12:42
@ha2hi
Copy link
Copy Markdown
Contributor Author

ha2hi commented Apr 8, 2026

@potiuk
I have resolved the pre-commit checks, successfully rebased with the main branch, and removed the unnecessary local test file (dags/test_dag.py).
The PR is now ready for review! Thank you for your patience and guidance.

@ha2hi ha2hi marked this pull request as draft April 9, 2026 10:58
@ha2hi ha2hi marked this pull request as ready for review April 9, 2026 10:59
@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds “delete job” support to the Databricks provider by introducing a new hook method for the Databricks Jobs Delete API and an accompanying operator, along with unit tests to validate the operator behavior.

Changes:

  • Added DatabricksHook.delete_job() calling the api/2.2/jobs/delete endpoint.
  • Introduced DatabricksDeleteJobsOperator that uses the hook to delete a job by job_id.
  • Added unit tests covering operator execution, hook initialization arguments, and template fields.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
providers/databricks/src/airflow/providers/databricks/hooks/databricks.py Adds a new delete_job hook method and endpoint constant for Jobs deletion.
providers/databricks/src/airflow/providers/databricks/operators/databricks.py Introduces DatabricksDeleteJobsOperator and wires it to the new hook method.
providers/databricks/tests/unit/databricks/operators/test_databricks.py Adds unit tests validating the new operator’s execution path and templating behavior.

Comment on lines +423 to +427
def __init__(
self,
*,
job_id: int,
databricks_conn_id: str = "databricks_default",
Deletes a Databricks job.

:param job_id: The ID of the Databricks job to delete. (templated)
:param databricks_conn_id: Reference to the Databricks connection.
Comment on lines +306 to +312
def delete_job(self, job_id: int) -> None:
"""
Call the ``api/2.2/jobs/delete`` endpoint.

:param job_id: The unique identifier of the job to be deleted.
"""
self._do_api_call(DELETE_ENDPOINT, {"job_id": job_id})
Comment on lines +623 to +628
# Verify that the DatabricksHook was initialized with the correct connection ID and default retry arguments
mock_hook_class.assert_called_once_with(
"databricks_default",
retry_limit=3,
retry_delay=1,
retry_args=None,
Comment on lines +436 to +440
self.databricks_conn_id = databricks_conn_id
self.polling_period_seconds = polling_period_seconds
self.databricks_retry_limit = databricks_retry_limit
self.databricks_retry_delay = databricks_retry_delay
self.databricks_retry_args = databricks_retry_args
REPAIR_RUN_ENDPOINT = ("POST", "2.2/jobs/runs/repair")
OUTPUT_RUNS_JOB_ENDPOINT = ("GET", "2.2/jobs/runs/get-output")
CANCEL_ALL_RUNS_ENDPOINT = ("POST", "2.2/jobs/runs/cancel-all")
DELETE_ENDPOINT = ("POST", "2.2/jobs/delete")
Copy link
Copy Markdown
Contributor Author

@ha2hi ha2hi Apr 11, 2026

Choose a reason for hiding this comment

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

I intentionally named it DELETE_ENDPOINT to maintain consistency with existing Job-related endpoints in this file, such as CREATE_ENDPOINT, RESET_ENDPOINT, and UPDATE_ENDPOINT, which do not include the JOB infix.

CREATE_ENDPOINT = ("POST", "2.2/jobs/create")
RESET_ENDPOINT = ("POST", "2.2/jobs/reset")
UPDATE_ENDPOINT = ("POST", "2.2/jobs/update")

To resolve this, I think we have three options:

  1. Change only this new endpoint : Rename it to DELETE_JOB_ENDPOINT as Copilot suggested.

  2. Rename all job endpoints : Add the JOB infix to all existing legacy endpoints (e.g., CREATE_JOB_ENDPOINT, RESET_JOB_ENDPOINT) for overall clarity.

  3. Maintain current convention : Keep it as DELETE_ENDPOINT to match the existing names in this module.

I lean towards Option 3 to avoid scope creep or potential breaking changes if anyone is importing those constants directly, but I'm fully open to whichever direction the maintainers prefer. Please let me know what you think!

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.

3 participants