🚸 Improve error message for invalid query parameter type annotations (#14479)

Co-authored-by: Anton.D <anton.dehtiarenko@chdp-tech.net>
Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
This commit is contained in:
Anton 2026-02-04 14:24:59 +01:00 committed by GitHub
parent ca4692a8c6
commit 41352de24c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -519,7 +519,7 @@ def analyze_param(
# For Pydantic v1
and getattr(field, "shape", 1) == 1
)
)
), f"Query parameter {param_name!r} must be one of the supported types"
return ParamDetails(type_annotation=type_annotation, depends=depends, field=field)

View File

@ -6,7 +6,10 @@ from pydantic import BaseModel
def test_invalid_sequence():
with pytest.raises(AssertionError):
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
@ -18,7 +21,10 @@ def test_invalid_sequence():
def test_invalid_tuple():
with pytest.raises(AssertionError):
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
@ -30,7 +36,10 @@ def test_invalid_tuple():
def test_invalid_dict():
with pytest.raises(AssertionError):
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
@ -42,7 +51,10 @@ def test_invalid_dict():
def test_invalid_simple_dict():
with pytest.raises(AssertionError):
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):