Repository: apache/airflow
File: airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_03_31.py (Python)

Code before:
    )


class RemoveUpstreamMapIndexesField(VersionChange):
    """Remove upstream_map_indexes field from TIRunContext - now computed by Task SDK."""

    description = __doc__

    instructions_to_migrate_to_previous_version = (
        schema(TIRunContext)
        .field("upstream_map_indexes")
        .existed_as(type=dict[str, int | list[int] | None] | None),
    )

    @convert_response_to_previous_version_for(TIRunContext)  # type: ignore[arg-type]
    def add_upstream_map_indexes_field(response: ResponseInfo) -> None:  # type: ignore[misc]
        """Add upstream_map_indexes field with None for older API versions."""
        response.body["upstream_map_indexes"] = None


class MakeDagRunStartDateNullable(VersionChange):
    """Make DagRun.start_date field nullable for runs that haven't started yet."""

    description = __doc__

    instructions_to_migrate_to_previous_version = ()

    @convert_response_to_previous_version_for(TIRunContext)  # type: ignore[arg-type]
    def ensure_start_date_in_ti_run_context(response: ResponseInfo) -> None:  # type: ignore[misc]
        """
        Ensure start_date is never None in DagRun for previous API versions.

        Older Task SDK clients expect start_date to be non-nullable. When the
        DagRun hasn't started yet (e.g. queued), fall back to run_after.
        """
        dag_run = response.body.get("dag_run")
        if isinstance(dag_run, dict) and dag_run.get("start_date") is None:
            dag_run["start_date"] = dag_run.get("run_after")

    @convert_response_to_previous_version_for(DagRun)  # type: ignore[arg-type]
    def ensure_start_date_in_dag_run(response: ResponseInfo) -> None:  # type: ignore[misc]
        """Ensure start_date is never None in direct DagRun responses for previous API versions."""
        if response.body.get("start_date") is None:
            response.body["start_date"] = response.body.get("run_after")


Review comment (suggestion):
```suggestion
    instructions_to_migrate_to_previous_version = (
        schema(DagRun).field("start_date").had(type=UtcDateTime),
    )
```

Code after:
        schema(TIDeferredStatePayload).field("next_kwargs").had(type=dict[str, Any]),
    )


class RemoveUpstreamMapIndexesField(VersionChange):
    """Remove upstream_map_indexes field from TIRunContext - now computed by Task SDK."""

    description = __doc__

    instructions_to_migrate_to_previous_version = (
        schema(TIRunContext)
        .field("upstream_map_indexes")
        .existed_as(type=dict[str, int | list[int] | None] | None),
    )

    @convert_response_to_previous_version_for(TIRunContext)  # type: ignore[arg-type]
    def add_upstream_map_indexes_field(response: ResponseInfo) -> None:  # type: ignore[misc]
        """Add upstream_map_indexes field with None for older API versions."""
        response.body["upstream_map_indexes"] = None


class AddNoteField(VersionChange):
    """Add note parameter to DagRun Model."""

    description = __doc__

    instructions_to_migrate_to_previous_version = (schema(DagRun).field("note").didnt_exist,)

    @convert_response_to_previous_version_for(TIRunContext)  # type: ignore[arg-type]
    def remove_note_field(response: ResponseInfo) -> None:  # type: ignore[misc]
        """Remove note field for older API versions."""
        if "dag_run" in response.body and isinstance(response.body["dag_run"], dict):
            response.body["dag_run"].pop("note", None)


class MakeDagRunStartDateNullable(VersionChange):
    """Make DagRun.start_date field nullable for runs that haven't started yet."""

    description = __doc__

    instructions_to_migrate_to_previous_version = (schema(DagRun).field("start_date").had(type=UtcDateTime),)

    @convert_response_to_previous_version_for(TIRunContext)  # type: ignore[arg-type]
    def ensure_start_date_in_ti_run_context(response: ResponseInfo) -> None:  # type: ignore[misc]
        """
        Ensure start_date is never None in DagRun for previous API versions.

        Older Task SDK clients expect start_date to be non-nullable. When the
        DagRun hasn't started yet (e.g. queued), fall back to run_after.
        """
        dag_run = response.body.get("dag_run")