Repository navigation
fix(airflow): stop an active run when deleting its DAG - #36349
Conversation
Airflow's delete_dag refuses while a task instance is running. The delete operation returned a 500 that OpenMetadata ignores, and OpenMetadata removes the ingestion pipeline before it calls Airflow, so the pipeline disappeared while its DAG stayed in Airflow and kept running on its schedule. The delete is a hard delete the user already confirmed, so when Airflow refuses, fail the DAG's unfinished runs and task instances the way kill does and delete again, in the same session. The kill operation now shares that step.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
…any running task Review follow-up: the delete fallback now stops runs only when Airflow refused because a task instance is running (other AirflowExceptions are re-raised untouched), and it fails unfinished task instances even when their run is no longer running. Kill keeps its behaviour; the never-true 'not instances' guard on a Query is dropped.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the DAG deletion retry and rollback changes.
No open issues 🎉
What changed in this PR
Addresses #36350 in OpenMetadata’s Airflow plugin by retrying DAG deletion after marking unfinished runs and tasks as failed, preventing running-task refusals from leaving orphan scheduled DAGs.
Changes:
- Shares run/task failure helpers between kill and delete, with deletion retried in the same transaction.
- Adds regression coverage for deleting running tasks and preserving active state when deletion fails.
- Records the deletion policy and rollback behavior in a decision record.
| File | Description |
|---|---|
openmetadata-airflow-apis/tests/integration/operations/test_dag_lifecycle.py |
Tests successful running-task deletion and rollback on refusal. |
openmetadata-airflow-apis/openmetadata_managed_apis/operations/kill_all.py |
Extracts shared helpers for failing unfinished runs and tasks. |
openmetadata-airflow-apis/openmetadata_managed_apis/operations/delete.py |
Handles running-task refusals and retries deletion before removing files. |
docs/decisions/2026-10-29-deleting-a-pipeline-dag-stops-its-active-run.md |
Documents the deletion policy, transaction guarantees, and consequences. |
Review effort: Balanced
Code Review ✅ Approved 2 closed / 2 findings🔴 High risk · Retrying DAG deletion after failing active runs removes Airflow records, potentially discarding in-progress execution state and task history. Deleting an ingestion pipeline now stops its active Airflow run and retries the DAG delete in the same session, so the run no longer outlives the confirmed delete. Resolved: delete is still refused when a task instance is running without a running or queued DagRun, and the stop-active-run rule is now documented beyond the PR description. No open issues found. ✅ 2 closed✅ Edge Case: Delete is still refused if a TI runs without a running/queued DagRun
✅ Quality: Delete-stops-active-run rule is only in the PR description
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
🚦 Removed from the merge queue —
|



Fixes #36350
Summary
Hard-deleting an ingestion pipeline while one of its tasks is running left the DAG in Airflow, still scheduled, with no pipeline in OpenMetadata.
Airflow's
delete_dagrefuses while a task instance is running. OpenMetadata removes the pipeline before it calls Airflow, and it ignores the 500 that comes back. Now, when Airflow refuses, the delete operation stops the active run (the same waykilldoes) and deletes again. The stop and the delete commit together, or roll back together: if the retried delete fails, the run is left as it was and the DAG files stay. The user already confirmed the delete, so the run should not outlive it.Follow-up from the review of the 2.0 backport #36267.
What changed
operations/delete.py: whendelete_dagrefuses because a task is running, fail the DAG's unfinished runs and task instances, then delete. Any other Airflow error is raised as before.operations/kill_all.py: the "fail unfinished runs" step moves intofail_unfinished_runsandfail_unfinished_task_instances, which kill and delete now share.set_statenow gets the caller's session, so the stop is not committed on its own before the delete. Kill's behaviour is unchanged.test_dag_lifecycle.py: the running-task test now expects the delete to succeed and remove everything. A new test checks that a failed delete leaves the run, task instance, DAG file and config untouched, with the task queued or running.docs/decisions/2026-10-29-deleting-a-pipeline-dag-stops-its-active-run.md: records why delete stops the run instead of refusing.No server change. Every delete path (direct, by name, async, force, service recursive, external app uninstall) goes through this one plugin endpoint.
Why not fail the delete with a 409 instead
I tried that first: the plugin returned 409, and OpenMetadata threw it from
IngestionPipelineRepository.postDelete. On main,cleanup()commits the delete in its own transaction beforepostDeletecalls the runner. So the user got a 409, but the pipeline was already gone and the DAG stayed. Keeping the pipeline would mean moving the runner teardown ahead of the DB delete for direct and cascade deletes, which is a much bigger change to the delete flow. Stopping the run fixes every path with a change inside the plugin only.Testing
Plugin tests (Airflow 3.3.2, SQLite):
tests/unit+tests/integration/operations, 70 passed, 1 skipped. The running-task delete test fails on main withTaskInstances still running; the failed-delete test with a running task fails without thesession=fix (the run was already committed as failed).ruff checkandruff format --checkare clean.test_airflow_ops.pyandingestion_pipeline/*need a live server and were not run here.Full stack: OpenMetadata server built from main, Postgres, ES 9.3, Airflow 3.3.2 with this plugin.
Delete while a task is running (6/6):
DELETE /ingestionPipelines/{id}?hardDelete=true(what the UI calls)DELETE /ingestionPipelines/name/{fqn}?hardDelete=trueDELETE /ingestionPipelines/async/{id}?hardDelete=true...&force=trueDELETE /databaseServices/{id}?hardDelete=true&recursive=truePOST /ingestionPipelines/kill/{id}on a running pipelineRegression (8/9, same as main):
The one failure is the harness calling
killafter its short run had already finished: Airflow answers 400 "no running runs", the same on main without this change.

Confidence Score: 5/5
The latest changes appear safe to merge; the earlier task-shutdown test gap remains non-blocking.Findings
Summary
The PR retries DAG deletion after marking unfinished runs and tasks as failed.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Delete DAG records] --> B{Airflow refuses?} B -->|No| F[Commit and remove files] B -->|Yes| C{Running task row exists?} C -->|No| D[Return the error and keep files] C -->|Yes| E[Mark unfinished runs and tasks failed] E --> G[Retry deletion in the same session] G --> FReviews (2) · Last reviewed commit: "fix(airflow): stop runs only for Airflow..." · Reviewed by Greptile