Fix dag run clear existing tasks#65628
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the “clear DAG run” dry-run behavior used by the UI by ensuring the API returns serializable TaskInstance data (with required relationships loaded) and correct “only new tasks” results.
Changes:
- Update
/dagRuns/{dag_run_id}/cleardry-run to query TaskInstances with proper eager-loading (and implement “only_new” via TI existence checks). - Add regression/integration tests covering full TaskInstanceResponse serialization and “only_failed” / “only_new” behaviors.
- Adjust the UI tasks table to hide the row-count heading inside the action accordion.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py | Reworks dry-run clear logic to avoid serialization failures and to compute “only_new” based on existing TIs. |
| airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py | Adds regression + integration tests for dry-run serialization and “only_new” behavior across DAG versions. |
| airflow-core/src/airflow/ui/src/components/ActionAccordion/ActionAccordion.tsx | Hides DataTable row-count heading in the affected-tasks table. |
Remove the two mocked only_new dry-run tests that patched SerializedDAG.clear and asserted it was called — the dry-run path no longer calls dag.clear() for only_new=True (it queries the DB directly for TI existence instead). Replace with a real DB-backed test: since DAG1_RUN1_ID already has TIs for all tasks in the latest DAG version, the endpoint correctly returns 0 new tasks. Also fix test_only_new_skips_task_that_already_has_ti to create the task_b TI via the non-dry-run API endpoint instead of constructing a bare TaskInstance object, which requires a task Operator and dag_version_id and would fail.
Backport failed to create: v3-2-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker 504694e v3-2-testThis should apply the commit to the v3-2-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
|
@bbovenzi can you help with backport PR? |
Clearing a Dag run with "Only existing tasks" or "Only failed tasks" was not working in the UI because the dry_run request to the api_server was erroring out with serialization failures.
Also fixed an issue where the dry run for "Only new tasks" could return a result to clear even if the task already existed.
Before:

After:

Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.