Skip to content

fix(airflow): delete DAGs through Airflow's delete_dag (2.0 backport of #33883) - #36267

Merged
sonika-shah merged 1 commit into
2.0from
backport/2.0-airflow-dag-delete-33883
Oct 27, 2026
Merged

sonika-shah merged 1 commit into
2.0from
backport/2.0-airflow-dag-delete-33883

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

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:

(psycopg2.errors.ForeignKeyViolation) update or delete on table "dag_version" violates foreign key
constraint "task_instance_dag_version_id_fkey" on table "task_instance"
[SQL: DELETE FROM dag WHERE dag.dag_id = %(dag_id_1)s]  path=/pluginsv2/api/v2/openmetadata/delete

Fix: delete.py now calls Airflow's own delete_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

Testing (Airflow 3.3.2): without the fix, both delete tests fail with FOREIGN KEY constraint failed on DELETE 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 publishSorted refactor, 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: PLC0415 markers were added to the test files because 2.0's ruff config doesn't ignore that rule for openmetadata-airflow-apis/tests (main ignores it globally). Those imports have to stay function-local.

RetriggerView in GreptileConfidence 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.

  • Airflow removes DAG history before the endpoint deletes its files.

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]
Loading

Reviews (1) · Last reviewed commit: "fix(airflow): delete DAGs through Airflo..." · Reviewed by Greptile

#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)
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 26, 2026
@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
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 delete_dag before removing DAG and config files, avoiding the foreign key violation on dag_version and keeping files in place when a delete is refused. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@sonika-shah
sonika-shah merged commit 819c0a4 into 2.0 Oct 27, 2026
79 of 84 checks passed
@sonika-shah
sonika-shah deleted the backport/2.0-airflow-dag-delete-33883 branch October 27, 2026 08:53

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants