]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Update internal annotation usage for compatibilty with Pydantic 2.11 (#13314)
authorVictorien <65306057+Viicos@users.noreply.github.com>
Fri, 28 Feb 2025 15:15:02 +0000 (16:15 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Feb 2025 15:15:02 +0000 (16:15 +0100)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
Co-authored-by: svlandeg <svlandeg@github.com>
fastapi/dependencies/utils.py
tests/test_analyze_param.py [new file with mode: 0644]

index e2866b48894b794c9fe7029a2c128b1751ff2754..09dd6f1b920f3aab9a71d071ff22f994fd38a38e 100644 (file)
@@ -449,15 +449,15 @@ def analyze_param(
             # We might check here that `default_value is RequiredParam`, but the fact is that the same
             # parameter might sometimes be a path parameter and sometimes not. See
             # `tests/test_infer_param_optionality.py` for an example.
-            field_info = params.Path(annotation=use_annotation)
+            field_info = params.Path(annotation=type_annotation)
         elif is_uploadfile_or_nonable_uploadfile_annotation(
             type_annotation
         ) or is_uploadfile_sequence_annotation(type_annotation):
-            field_info = params.File(annotation=use_annotation, default=default_value)
+            field_info = params.File(annotation=type_annotation, default=default_value)
         elif not field_annotation_is_scalar(annotation=type_annotation):
-            field_info = params.Body(annotation=use_annotation, default=default_value)
+            field_info = params.Body(annotation=type_annotation, default=default_value)
         else:
-            field_info = params.Query(annotation=use_annotation, default=default_value)
+            field_info = params.Query(annotation=type_annotation, default=default_value)
 
     field = None
     # It's a field_info, not a dependency
diff --git a/tests/test_analyze_param.py b/tests/test_analyze_param.py
new file mode 100644 (file)
index 0000000..9fd3fa6
--- /dev/null
@@ -0,0 +1,22 @@
+from inspect import signature
+
+from fastapi.dependencies.utils import ParamDetails, analyze_param
+from pydantic import Field
+from typing_extensions import Annotated
+
+from .utils import needs_pydanticv2
+
+
+def func(user: Annotated[int, Field(strict=True)]): ...
+
+
+@needs_pydanticv2
+def test_analyze_param():
+    result = analyze_param(
+        param_name="user",
+        annotation=signature(func).parameters["user"].annotation,
+        value=object(),
+        is_path_param=False,
+    )
+    assert isinstance(result, ParamDetails)
+    assert result.field.field_info.annotation is int