]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🚸 Improve error message for invalid query parameter type annotations (#14479)
authorAnton <34218036+retwish@users.noreply.github.com>
Wed, 4 Feb 2026 13:24:59 +0000 (14:24 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Feb 2026 13:24:59 +0000 (14:24 +0100)
Co-authored-by: Anton.D <anton.dehtiarenko@chdp-tech.net>
Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
fastapi/dependencies/utils.py
tests/test_invalid_sequence_param.py

index 2afc734ba4b137ec3ba2331c4691db9847c64d8c..b647818c4b6fd6b45b3f25f3c75b50ce5f4e8c90 100644 (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)
 
index 2b8fd059e1c192bc0766b7f92928acf35be893c1..3695344f7a4acaa03dcbd8b63fc3746624ffd070 100644 (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):