Unwrap Annotated[T, ...] inside find_graphene_type#115
Open
vishwa2710 wants to merge 1 commit intographql-python:mainfrom
Open
Unwrap Annotated[T, ...] inside find_graphene_type#115vishwa2710 wants to merge 1 commit intographql-python:mainfrom
vishwa2710 wants to merge 1 commit intographql-python:mainfrom
Conversation
Pydantic v2 strips top-level Annotated metadata from FieldInfo.annotation, but does not strip Annotated inside Union arms or generic containers, so Optional[PositiveFloat] reaches find_graphene_type as Union[Annotated[float, Gt(gt=0)], None]. The inner arm was dispatched to convert_generic_python_type and raised ConversionError. This affected every constrained pydantic scalar (PositiveFloat, PositiveInt, NonNegativeInt, conint(...), confloat(...)) inside Optional or any container, plus user-defined Annotated[T, ...] aliases in the same positions. Unwrap Annotated[T, ...] -> T at the entry point alongside the existing PEP 604 UnionType normalization. Constraints (Gt, Le, etc.) are already enforced by pydantic at validation time and have no GraphQL representation, so dropping them at conversion is correct. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pydantic v2 strips top-level
Annotatedmetadata fromFieldInfo.annotation, sox: PositiveFloatreaches the converter as barefloat. However, pydantic does not stripAnnotatedinsideUnionarms or generic containers, sox: Optional[PositiveFloat]reachesfind_graphene_typeasUnion[Annotated[float, Gt(gt=0)], None]. The inner arm gets dispatched toconvert_generic_python_type(becauseAnnotated.__origin__is the inner type) and raisesConversionError.This affects every constrained pydantic scalar —
PositiveFloat,PositiveInt,NonNegativeInt,conint(...),confloat(...)— whenever it appears insideOptional, alist, or any other container. It also breaks user-definedAnnotated[T, ...]aliases in the same positions.Recursive call sites (
convert_union_type,convert_generic_python_type) re-enterfind_graphene_typeand benefit automatically.(Created with help from Claude Code)