Skip to content

🐛 Fix handling sequences with nested Annotated types#14874

Open
YuriiMotov wants to merge 4 commits intomasterfrom
fix-nested-annotated-types-in-field_annotation_is_scalar_sequence
Open

🐛 Fix handling sequences with nested Annotated types#14874
YuriiMotov wants to merge 4 commits intomasterfrom
fix-nested-annotated-types-in-field_annotation_is_scalar_sequence

Conversation

@YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Feb 9, 2026

Currently on master branch the following code example fails on startup:

from typing import Annotated

from fastapi import FastAPI, Query
from pydantic import Field

MaxSizedSet = Annotated[set[str], Field(max_length=3)]

app = FastAPI()


@app.get("/")
def read_root(foo: Annotated[MaxSizedSet | None, Query()] = None):
    return {"foo": foo}
  File "/home/yurii/code/fastapi/fastapi/dependencies/utils.py", line 521, in analyze_param
    is_scalar_field(field)
AssertionError: Query parameter 'foo' must be one of the supported types

(the error traceback is a bit misleading - the issue is actually not in is_scalar_field, but in field_annotation_is_scalar_sequence which is a part of the same assert)

This is because field_annotation_is_scalar_sequence doesn't unwrap Annotated.

We also need to unwrap Annotated in field_annotation_is_sequence to make _get_multidict_value correctly recognize this parameter as sequence and extract the value using get_list.


See: #14852

@YuriiMotov YuriiMotov added the bug Something isn't working label Feb 9, 2026
@YuriiMotov YuriiMotov force-pushed the fix-nested-annotated-types-in-field_annotation_is_scalar_sequence branch from fd31d1d to 1aa1a62 Compare February 9, 2026 11:07
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 9, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing fix-nested-annotated-types-in-field_annotation_is_scalar_sequence (1a18de1) with master (3da206c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (d06ab3f) during the generation of this report, so 3da206c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@YuriiMotov YuriiMotov force-pushed the fix-nested-annotated-types-in-field_annotation_is_scalar_sequence branch from 1aa1a62 to cda2003 Compare February 9, 2026 12:12
@YuriiMotov YuriiMotov changed the title 🐛 Fix handling nested Annotated types in field_annotation_is_scalar_sequence 🐛 Fix handling sequences with nested Annotated types Feb 9, 2026
@YuriiMotov YuriiMotov marked this pull request as ready for review February 12, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants