"""
    Fetch a date attribute or None of it does not exist.
    :param task_instance: the task instance
    :param attr: the attribute name
    :meta private:
    """
    result: datetime | None = getattr(task_instance, attr, None)
    return result.strftime("%Y%m%dT%H%M%S") if result else ""
def _get_previous_ti(
    *,
    task_instance: TaskInstance | TaskInstancePydantic,
    session: Session,
    state: DagRunState | None = None,
) -> TaskInstance | TaskInstancePydantic | None:
    """
    The task instance for the task that ran before this task instance.
    :param task_instance: the task instance
    :param state: If passed, it only take into account instances of a specific state.