mirror of https://github.com/tiangolo/fastapi.git
♻️ Update tests and internals for compatibility with Pydantic >=2.10 (#12971)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
8c29eaec25
commit
bf4fad1fda
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue