Skip to content

Airflow 3 equivalent for get_previous_ti #59609

Closed

Description

@BasPH

Description

A user ran this code in Airflow 2:

prev_ti = ti.get_previous_ti(state='success')
# do something with prev_ti.start_date

This doesn't work anymore on Airflow 3, since the context gives a RuntimeTaskInstance with limited functionality. I found the business logic:

  1. Fetches the previous successful DagRun, and
  2. Returns the corresponding task instance (regardless state, which is a bit odd, but not the point right now).

Step 1 is reproducible in Airflow 3:

@task
def test(ti: RuntimeTaskInstance):
    prev_dagrun = ti.get_previous_dagrun(state=DagRunState.SUCCESS)

But step 2 is not, there's no way to fetch a specific task from that object.

Can we introduce an Airflow 3-equivalent?

Note: if we re-implement ti.get_previous_ti(state='success') for Airflow 3 we could consider actually returning the last successful task instance, instead of the task instance (regardless state) of the last successful Dag Run.

Use case/motivation

Migrate to Airflow 3

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Dec 18, 2025
  2. jroachgolf84 commented on Dec 18, 2025

    @jroachgolf84
    Collaborator

    I think the change would need to be made here?

    class RuntimeTaskInstance(TaskInstance):

  3. added and removed
    needs-triage
    on Dec 18, 2025
  4. dstandish commented on Dec 18, 2025

    @dstandish
    Contributor

    So....

    I would like to complicate this.

    The notion of "previous TI" is somewhat ambiguous.

    Do we mean by run date or by logical date, for example?

    And we are adding the concept of partitions to airflow, which will have its own sense of "previous".

    Do you think there is a way that we can avoid fixing this (to avoid the ambiguity) ?

    What is the use case?

  5. self-assigned this
    on Dec 22, 2025
  6. added a commit that references this issue on Feb 8, 2026
    80ba657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions