diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index 8784d5afc..c5ac1f660 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -372,6 +372,7 @@ def get_model_fields(model: Type[BaseModel]) -> List[ModelField]: for name, field_info in model.model_fields.items() ] + # Duplicate of several schema functions from Pydantic v1 to make them compatible with # Pydantic v2 and allow mixing the models diff --git a/fastapi/datastructures.py b/fastapi/datastructures.py index 3df81087b..34185b96a 100644 --- a/fastapi/datastructures.py +++ b/fastapi/datastructures.py @@ -11,7 +11,6 @@ from typing import ( ) from fastapi._compat import ( - PYDANTIC_V2, CoreSchema, GetJsonSchemaHandler, JsonSchemaValue, diff --git a/fastapi/encoders.py b/fastapi/encoders.py index beab3e446..8ff7d58dd 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -25,7 +25,7 @@ from pydantic.networks import AnyUrl, NameEmail from pydantic.types import SecretBytes, SecretStr from typing_extensions import Annotated, Doc -from ._compat import PYDANTIC_V2, Url, _is_undefined, _model_dump +from ._compat import Url, _is_undefined, _model_dump # Taken from Pydantic v1 as is diff --git a/tests/test_pydantic_v1_v2_multifile/main.py b/tests/test_pydantic_v1_v2_multifile/main.py index d7095b551..90f525bba 100644 --- a/tests/test_pydantic_v1_v2_multifile/main.py +++ b/tests/test_pydantic_v1_v2_multifile/main.py @@ -113,4 +113,3 @@ def handle_v2_list_to_v1_item(data: List[modelsv2.Item]) -> modelsv1.Item: multi=[modelsv1.SubItem(name=s.new_sub_name) for s in item.new_multi], ) return modelsv1.Item(title="", size=0, sub=modelsv1.SubItem(name="")) -