From 2ba181e1bb0091fb06f7b7995b210e9f9dd9d52b Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 25 Sep 2025 12:45:36 +0100 Subject: [PATCH] Use explicit pydantic version check --- fastapi/_compat.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fastapi/_compat.py b/fastapi/_compat.py index d6c109521..311b265a5 100644 --- a/fastapi/_compat.py +++ b/fastapi/_compat.py @@ -115,13 +115,11 @@ if PYDANTIC_V2: # (e.g. `TypeAdapter(Annotated[int, Field(alias='b')])`). In some cases, we # end up building the type adapter from a model field annotation so we # need to ignore the warning: - try: + if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 12): # pragma: no cover from pydantic.warnings import ( # type: ignore[attr-defined] UnsupportedFieldAttributeWarning, ) - except ImportError: # pragma: no cover - pass - else: # pragma: no cover + warnings.simplefilter( "ignore", category=UnsupportedFieldAttributeWarning )