Repository navigation
fix(airflow): delete DAGs through Airflow's delete_dag (2.0 backport of #33883) - #36267
Conversation
#33883) Deleting an ingestion pipeline whose DAG has run before failed with a 500: delete.py ran a bare `DELETE FROM dag`, which Airflow 3 rejects because task_instance.dag_version_id still references the DAG's versions (task_instance_dag_version_id_fkey). Use Airflow's own delete_dag, which removes runs, task instances and versions in FK order, and run it before removing the DAG/config files so a refused delete (task still running) leaves the files for Airflow to re-parse. Only the DAG-delete part of #33883 is backported; the rest of that PR depends on main-only changes. (cherry picked from commit 469beff, partial)
❌ 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 |
Code Review ✅ Approved🔴 High risk · Calling Airflow's delete_dag removes DAG runs, task instances, and versions, potentially erasing execution history for deleted ingestion pipelines. Backports the DAG-delete fix to 2.0 so deleting an ingestion pipeline calls Airflow's 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 |
|



Backport of the DAG-delete fix from #33883 to
2.0.Issue: on 2.0, deleting an ingestion pipeline whose DAG has run before returns 500 and leaves the DAG in Airflow:
Fix:
delete.pynow calls Airflow's owndelete_dag, which removes runs, task instances and DAG versions in FK order, and runs it before removing the DAG/config files, so a refused delete (a task is still running) leaves the files in place for Airflow to re-parse.What changed
operations/delete.py: taken as-is from maintests/integration/operations/test_dag_lifecycle.py: the two delete tests from fix: bulk backend + Airflow + integration-test refresh (17 files) #33883 (DAG with versioned task history deletes cleanly; a running DAG keeps its files)tests/conftest.py: from fix: bulk backend + Airflow + integration-test refresh (17 files) #33883 (setsAIRFLOW_HOMEbefore Airflow imports and runsinitdb)tests/unit/test_operation_diagnostics.py: mockairflow_delete_daginstead of the old session pathTesting (Airflow 3.3.2): without the fix, both delete tests fail with
FOREIGN KEY constraint failedonDELETE FROM dag; with the fix, they and the unit suite pass. Ruff is clean with the 2.0 config.Why only part of #33883
#33883 bundled 17 files. The rest of it (deploy readiness wait, spawn-based DAG scan, run-id helper, DataContract result lookup, lifecycle dispatcher snapshot, IngestionPipelineRepository undeployed delete) builds on main-only changes such as #33515 and the dispatcher
publishSortedrefactor, and none of it is needed for this bug. If any of those are needed on 2.0, they should be backported separately.Two
# noqa: PLC0415markers were added to the test files because 2.0's ruff config doesn't ignore that rule foropenmetadata-airflow-apis/tests(main ignores it globally). Those imports have to stay function-local.

Confidence Score: 5/5
This backport appears safe to merge; no actionable issues were found.Summary
This backport replaces direct database deletes with Airflow’s
delete_dag.No actionable issues were found. Tests were not run during this review.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Delete request] --> B[Call Airflow delete_dag] B -->|Deletion refused| C[Return error and keep files] B -->|DAG missing| D[Record zero deleted rows] B -->|Deletion succeeds| E[Commit database changes] D --> E E --> F[Remove DAG and config files] F --> G[Return existing success or partial-delete response]Reviews (1) · Last reviewed commit: "fix(airflow): delete DAGs through Airflo..." · Reviewed by Greptile