Skip to content

Support backfilling a subset of a Dag's tasks - #71978

Open
Fury0508 wants to merge 5 commits into
apache:mainfrom
Fury0508:support-backfill-subset-of-tasks
Open

Support backfilling a subset of a Dag's tasks#71978
Fury0508 wants to merge 5 commits into
apache:mainfrom
Fury0508:support-backfill-subset-of-tasks

Conversation

@Fury0508

Copy link
Copy Markdown
Contributor

Backfills can now target a subset of a Dag's tasks via a task_id_pattern regular expression, instead of always covering the whole graph.

Motivating cases from the issue: rebuilding one dataset among many written by a single Dag, and excluding a historical sensor whose external data has since been pruned and can no longer succeed.

Behaviour

  • task_id_pattern is resolved to the matching task ids at creation time and persisted on the backfill (selected_task_ids), so the selection stays reproducible even if the Dag later changes.
  • The scheduler restricts the run to the selected tasks by pruning the run's Dag to that subset (reusing SerializedDAG.partial_subset). Dependencies on unselected upstream tasks are ignored, and run success is judged on the selected tasks alone.
  • Requests whose pattern matches no task are rejected (422); an invalid regex is rejected too.
  • Omitting the pattern backfills the whole Dag exactly as before — the new column is nullable, so existing backfills are unaffected.

Scope of this PR: model + migration + REST API + scheduler semantics + tests. CLI and UI form controls are intended as follow-ups.

closes: #70027


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code

Operators sometimes need to re-run only part of a Dag: to rebuild a single
dataset among many written by one Dag, or to exclude a historical sensor whose
external data has since been pruned and can no longer succeed. Until now a
backfill always covered the whole graph, forcing users to either re-run
everything or restructure their Dags.

A backfill can now take a task_id_pattern regular expression. The matching
tasks are resolved and persisted with the backfill so the selection stays
reproducible if the Dag later changes, and the scheduler restricts the run to
those tasks by pruning the run's Dag to the selected subset. Dependencies on
unselected upstream tasks are ignored, and run success is judged on the
selected tasks alone. Omitting the pattern backfills the whole Dag as before.

closes: apache#70027
Comment thread airflow-core/src/airflow/models/backfill.py Fixed
Compiling a user-supplied regular expression for task selection is a
denial-of-service vector (catastrophic backtracking), flagged by CodeQL.
Select tasks by plain substring containment instead, mirroring how
SerializedDAG.partial_subset already resolves a string selector, so no
untrusted pattern is ever compiled. Regenerate the OpenAPI spec, the UI
client, and the airflow-ctl datamodels to match the updated field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:db-migrations PRs with DB migration area:UI Related to UI/UX. For Frontend Developers. kind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Backfills for a subset of Tasks

2 participants