Skip to content

Allow task to depend on specific tasks from previous dag_run #60328

Open

Description

@bujji8411

Description

depends_on_past=True currently allows a task to depend only on the same task in the previous dag_run.

There is no native way for a task to depend on the successful completion of multiple specific tasks from the previous dag_run (within the same DAG). Achieving this today requires custom sensors that directly query Airflow metadata tables.

Use case/motivation

In stateful or partially retryable pipelines, it is common to require that a group of tasks in the previous dag_run has completed successfully before continuing execution in the next run.

Example:

A → B → C → D → E

If:
dag_run_1 fails at task D
Then for dag_run_2: Task C should not start until C, D, and E from dag_run_1 have all succeeded
Today:
depends_on_past is insufficient (checks only the same task)
trigger_rule applies only within the same dag_run
Users must implement custom PythonSensors that query DagRun / TaskInstance
This adds boilerplate, DB coupling, and operational complexity for a fairly common dependency pattern.

What would you like to happen?
Provide a declarative, first-class way for a task to depend on specific tasks from the previous dag_run.

Illustrative example (API shape open for discussion):

C = PythonOperator(
    task_id="C",
    depends_on_past=True,
    depends_on_previous_task_ids=["C", "D", "E"],
)

Semantics:

In dag_run(N), task C is scheduled only if the listed tasks in dag_run(N-1) all finished with success
First dag_run is not blocked
Backward compatible and fully opt-in
This would remove the need for custom sensors while keeping cross-run dependencies explicit and readable.

Related issues

No known existing issue covering this specific capability.

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. boring-cyborg commented on Jan 9, 2026

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  2. abhijeets25012-tech commented on Jan 9, 2026

    @abhijeets25012-tech
    Contributor

    i would like to contribute

  3. SameerMesiah97 commented on Jan 9, 2026

    @SameerMesiah97
    Contributor

    i would like to contribute

    You are free to open a PR but I would advise you to review the existing PR once it is done or pick another issue you feel you can handle.

  4. Parthsuii commented on Jan 10, 2026

    @Parthsuii

    Hi I’d like to work on this

  5. shashbha14 commented on Jan 12, 2026

    @shashbha14
    Contributor

    I would like to work on this issue.

  6. yuseok89 commented on Aug 18, 2026

    @yuseok89
    Contributor

    Before adding a new parameter, I wanted to check whether the same behaviour can be had with what's already there, and see whether it covers your case.

    In the example from the issue, C needs {C, D, E}, which is exactly "C itself plus everything transitively downstream of C". wait_for_downstream=True does almost that. It turns on depends_on_past as well and then additionally waits on downstream tasks, but only immediately downstream ones. So setting it on C covers {C, D} and misses E.

    downstream_task_ids is just a set, and adding a transitive edge doesn't change execution order (the chain already enforces it), so a single edge closes that gap.

    A >> B >> C >> D >> E
    C >> E   # transitive edge, same execution order, just widens C's direct downstream
    
    C = PythonOperator(
        task_id="C",
        wait_for_downstream=True,   # implies depends_on_past=True
        ...
    )

    wait_for_downstream now covers {D, E} and the implied depends_on_past covers C, giving {C, D, E}. The first Dag run isn't blocked either, since the check passes when there's no previous run.

    Would this work in your actual pipeline, or does it miss something? If it covers the case, documenting the pattern under wait_for_downstream might be more useful than a new argument. If it doesn't, knowing why would sharpen the case for a first-class parameter.

  7. mahesh-desu commented on Sep 25, 2026

    @mahesh-desu

    I'd like to work on this - plan to check wait_for_downstream coverage first, then propose prev_task_ids semantics building on #64653 (batch query, parse-time validation, XCom path). May I proceed?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions