]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Update tests and internals for compatibility with Pydantic >=2.10 (#12971)
authorTamir Duberstein <tamird@gmail.com>
Fri, 22 Nov 2024 17:09:25 +0000 (12:09 -0500)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2024 17:09:25 +0000 (18:09 +0100)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
fastapi/_compat.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an_py310.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an_py39.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_py310.py

index 2b4d3e725af0f288d4d7990cd8ac92ea11416aa4..c07e4a3b002c39bb29c40afdd2c3ed9f20b94595 100644 (file)
@@ -21,12 +21,10 @@ from typing import (
 from fastapi.exceptions import RequestErrorModel
 from fastapi.types import IncEx, ModelNameMap, UnionType
 from pydantic import BaseModel, create_model
-from pydantic.version import VERSION as P_VERSION
+from pydantic.version import VERSION as PYDANTIC_VERSION
 from starlette.datastructures import UploadFile
 from typing_extensions import Annotated, Literal, get_args, get_origin
 
-# Reassign variable to make it reexported for mypy
-PYDANTIC_VERSION = P_VERSION
 PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])
 PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2
 
@@ -47,6 +45,8 @@ sequence_annotation_to_type = {
 
 sequence_types = tuple(sequence_annotation_to_type.keys())
 
+Url: Type[Any]
+
 if PYDANTIC_V2:
     from pydantic import PydanticSchemaGenerationError as PydanticSchemaGenerationError
     from pydantic import TypeAdapter
index 945cee3d2628299bcae8f121aa40bfb0807a75bc..4f52d6ff7542a6c5332103fd7dc12d9bdbf42e45 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 from dirty_equals import IsDict
+from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
 from fastapi.testclient import TestClient
 
 
@@ -107,6 +108,12 @@ def test_openapi_schema(client: TestClient):
                                     ],
                                     "title": "Query string",
                                     "description": "Query string for the items to search in the database that have a good match",
+                                    # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34.
+                                    **(
+                                        {"deprecated": True}
+                                        if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
+                                        else {}
+                                    ),
                                 }
                             )
                             | IsDict(
index 23951a9aa37b15beabf355a29d65dbd9d5b96640..5daca1e70148701e6b41191c4fb505cac3644019 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 from dirty_equals import IsDict
+from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
 from fastapi.testclient import TestClient
 
 
@@ -107,6 +108,12 @@ def test_openapi_schema(client: TestClient):
                                     ],
                                     "title": "Query string",
                                     "description": "Query string for the items to search in the database that have a good match",
+                                    # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34.
+                                    **(
+                                        {"deprecated": True}
+                                        if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
+                                        else {}
+                                    ),
                                 }
                             )
                             | IsDict(
index 2968af563c864a0326a35720e0675bbc3ad3f75f..89da4d82ea56bb19cb0bfd166856e8b4d5342151 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 from dirty_equals import IsDict
+from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
 from fastapi.testclient import TestClient
 
 from ...utils import needs_py310
@@ -114,6 +115,12 @@ def test_openapi_schema(client: TestClient):
                                     ],
                                     "title": "Query string",
                                     "description": "Query string for the items to search in the database that have a good match",
+                                    # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34.
+                                    **(
+                                        {"deprecated": True}
+                                        if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
+                                        else {}
+                                    ),
                                 }
                             )
                             | IsDict(
index 534ba87594ee0c81f1273ac87f857b7c49e68395..f5f692b0695cb01c6996af069bd799da423b69b8 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 from dirty_equals import IsDict
+from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
 from fastapi.testclient import TestClient
 
 from ...utils import needs_py39
@@ -114,6 +115,12 @@ def test_openapi_schema(client: TestClient):
                                     ],
                                     "title": "Query string",
                                     "description": "Query string for the items to search in the database that have a good match",
+                                    # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34.
+                                    **(
+                                        {"deprecated": True}
+                                        if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
+                                        else {}
+                                    ),
                                 }
                             )
                             | IsDict(
index 886bceca21de3e3dc86e2501aa2d7850789b826c..5b62c969fb7c361a5e52284b1f9cdf234d9fcb4e 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 from dirty_equals import IsDict
+from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
 from fastapi.testclient import TestClient
 
 from ...utils import needs_py310
@@ -114,6 +115,12 @@ def test_openapi_schema(client: TestClient):
                                     ],
                                     "title": "Query string",
                                     "description": "Query string for the items to search in the database that have a good match",
+                                    # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34.
+                                    **(
+                                        {"deprecated": True}
+                                        if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
+                                        else {}
+                                    ),
                                 }
                             )
                             | IsDict(