Skip to content

Stop passing lazy queries into Iterable[] API response fields #76683

Closed

Description

@henry3260

Body

An Iterable[...] response field is validated lazily, so its rows are fetched while FastAPI serializes the response — on the event loop, on the sync engine. Once the connection pool is busy, that blocks the whole API server.

The seven routes below hand the field the lazy session.scalars(...) directly. #74247 and #76525 fixed the same shape for pools, dags and deadlines. #76537 adds a test that lists these seven in generated/known_lazy_response_fields.txt as strict xfails, so the list cannot grow.

Field, then the route that feeds it lazily.

  • AssetAliasCollectionResponse.asset_aliases — routes/public/assets.py:377
  • BackfillCollectionResponse.backfills — routes/public/backfills.py:114 (the UI route already builds a list)
  • ConnectionCollectionResponse.connections — routes/public/connections.py:253
  • DAGVersionCollectionResponse.dag_versions — routes/public/dag_versions.py:223
  • DAGWarningCollectionResponse.dag_warnings — routes/public/dag_warning.py:76
  • DeadlineAlertCollectionResponse.deadline_alerts — routes/ui/deadlines.py:237
  • VariableCollectionResponse.variables — routes/public/variables.py:127

How to fix

  1. Annotate the field list[X] instead of Iterable[X], and materialize at the route with .all() or list(...). The OpenAPI schema is unchanged, so no client is affected.
  2. Eager-load anything the items resolve on access, or serialization still runs a query per item.
  3. Delete the field's line from generated/known_lazy_response_fields.txt. Each line is a strict xfail, so the run fails until it is removed.

One field per PR is fine.

Not in scope

Thirteen other Iterable[...] fields are exempt: their routes resolve the items first, and Iterable there is the deliberate choice from #57878.

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Activity

  1. added
    kind:meta
    area:API
    on Nov 7, 2026
  2. its-amann commented on Nov 7, 2026

    @its-amann

    working on the connections and variables ones, will open a PR for each

  3. henry3260 commented on Nov 7, 2026

    @henry3260
    MemberAuthor

    working on the connections and variables ones, will open a PR for each

    Maybe you should wait for our discussion in #76537

  4. henry3260 commented on Nov 8, 2026

    @henry3260
    MemberAuthor

    We only need to fix one place, so we don't need to open pr to track this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:APIkind:meta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions