*,
    task_instance: TaskInstance | TaskInstancePydantic,
    state: DagRunState | None = None,
    session: Session | None = None,
) -> DagRun | None:
    """
    The DagRun that ran before this task instance's DagRun.
    :param task_instance: the task instance
    :param state: If passed, it only take into account instances of a specific state.
    :param session: SQLAlchemy ORM Session.
    :meta private:
    """
    dag = task_instance.task.dag
    if dag is None:
        return None
    dr = task_instance.get_dagrun(session=session)
    dr.dag = dag