https://github.com/apache/airflow/blob/main/airflow/cli/commands/task_command.py#L145
self,
        task_id: str,
        session: Session = NEW_SESSION,
        *,
        map_index: int = -1,
    ) -> TI | None:
        """
        Return the task instance specified by task_id for this dag run.
        :param task_id: the task id
        :param session: Sqlalchemy ORM Session
        """
        from airflow.models.dagrun import DagRun
        return DagRun.fetch_task_instance(
            dag_id=self.dag_id,
            dag_run_id=self.run_id,
            task_id=task_id,
            session=session,
            map_index=map_index,
        )
DagRunPydantic.model_rebuild()