diff --git a/fastapi/_compat.py b/fastapi/_compat.py index 2233fe33c..9ffcaf409 100644 --- a/fastapi/_compat.py +++ b/fastapi/_compat.py @@ -56,7 +56,6 @@ if PYDANTIC_V2: from pydantic.json_schema import GenerateJsonSchema as GenerateJsonSchema from pydantic.json_schema import JsonSchemaValue as JsonSchemaValue from pydantic_core import CoreSchema as CoreSchema - from pydantic_core import MultiHostUrl as MultiHostUrl from pydantic_core import PydanticUndefined, PydanticUndefinedType from pydantic_core import Url as Url from pydantic_core.core_schema import ( @@ -294,9 +293,6 @@ else: from pydantic.fields import ( # type: ignore[no-redef, attr-defined] UndefinedType as UndefinedType, # noqa: F401 ) - from pydantic.networks import ( # type: ignore[no-redef] - MultiHostDsn as MultiHostUrl, # noqa: F401 - ) from pydantic.schema import ( field_schema, get_flat_models_from_fields, diff --git a/fastapi/encoders.py b/fastapi/encoders.py index b542749f2..30493697e 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -20,10 +20,10 @@ from uuid import UUID from fastapi.types import IncEx from pydantic import BaseModel from pydantic.color import Color -from pydantic.networks import NameEmail +from pydantic.networks import AnyUrl, NameEmail from pydantic.types import SecretBytes, SecretStr -from ._compat import PYDANTIC_V2, MultiHostUrl, Url, _model_dump +from ._compat import PYDANTIC_V2, Url, _model_dump # Taken from Pydantic v1 as is @@ -80,7 +80,7 @@ ENCODERS_BY_TYPE: Dict[Type[Any], Callable[[Any], Any]] = { set: list, UUID: str, Url: str, - MultiHostUrl: str, + AnyUrl: str, }