Use min_length and max_length on request bodies so the server imports on FastAPI 0.155

Merged
BU
1mo ago
+185-18

FastAPI 0.155.0 (released 2026-10-20) removed the deprecated catch-all **extra from Path, Query, Header, Cookie, Body, Form and File, so an unknown keyword now raises TypeError. Six request parameters in the server API passed keywords FastAPI never had, so on a fresh install that resolves FastAPI 0.155, prefect.server.api fails to import:

TypeError: Body() got an unexpected keyword argument 'min_items'

This switches them to the keywords FastAPI does have:

  • min_items=1 to min_length=1 on names for POST /v2/concurrency_limits/increment, /increment-with-lease and /decrement
  • max_items=200 to max_length=200 on the id lists for POST /ui/flow_runs/count-task-runs, /ui/flows/count-deployments and /ui/flows/next-runs

On FastAPI before 0.155 the old keywords were never validated. They were copied into the OpenAPI schema as non-standard min_items/max_items keys and nothing else, so the new keywords start enforcing limits that were only documented:

  • An empty names now returns 422 on the three concurrency slot endpoints. Before, it returned 200; on increment-with-lease it created a lease that held no limits. The SDK's concurrency() and rate_limit() return early on empty names (since #14789), so they never send one, but a direct client.increment_concurrency_slots([]) or client.release_concurrency_slots([]) now raises.
  • More than 200 ids now returns 422 on the three UI routes. The UIs send at most one page of ids (the server caps pages at PREFECT_SERVER_API_DEFAULT_LIMIT, 200 by default) or batch them at 200.

tests/server/api/test_fastapi_param_keywords.py checks every FastAPI request-parameter call in src/prefect/ against the function's real signature. CI runs the locked FastAPI 0.141.1, which accepts unknown keywords without a warning, so without it the next one would pass CI and fail installs. The regenerated docs/v3/api-ref/rest-api/server/schema.json changes only these six fields, now standard minItems/maxItems.

There is no linked issue: this fixes an import failure on the current FastAPI release.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • No issue exists; this is a fix for an import failure on FastAPI 0.155.
  • If this pull request adds or changes functionality, it includes tests or explains why tests are not needed.
  • If this pull request changes user-facing behavior, it updates documentation or explains why documentation is not needed.
    • The regenerated REST API schema documents the enforced limits.
  • If this pull request removes docs files, it includes redirect settings in mint.json.
    • No docs files removed.
  • If this pull request adds functions or classes, it includes helpful docstrings.