ConversionError for constrained pydantic scalars (PositiveFloat, PositiveInt, conint, …) inside Optional or generic containers
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
Research direction
Start with find_graphene_type and convert_generic_python_type, using the Optional[PositiveFloat] example in the issue to reproduce the ConversionError. Check the handling of Annotated types inside unions and generic containers; done means constrained scalars and user-defined Annotated aliases convert without raising.
Written by the indexing model from the issue text.
Description
find_graphene_type raises ConversionError whenever a constrained pydantic scalar appears inside Optional[...], list[...], or any other container. This
affects every Annotated[T, ...]-based pydantic type — PositiveFloat, PositiveInt, NonNegativeInt, conint(...), confloat(...), etc. — as well as user-defined
Annotated aliases.
from typing import Optional
from pydantic import BaseModel, PositiveFloat
from graphene_pydantic import PydanticObjectType
class M(BaseModel):
x: Optional[PositiveFloat] = None
class GM(PydanticObjectType):
class Meta:
model = M
Result:
graphene_pydantic.converters.ConversionError: Don't know how to handle
typing.Annotated[float, Gt(gt=0)] (generic: <class 'float'>) ```
Pydantic v2 only strips Annotated at the top level of FieldInfo.annotation. Inside a Union arm or a generic container the wrapper is preserved, so the inner
arm of Optional[PositiveFloat] reaches find_graphene_type as Annotated[float, Gt(gt=0)]. That has an __origin__ (the inner float), so it falls into
convert_generic_python_type, which doesn't recognize the shape and raises.
Affected versions
- graphene-pydantic==0.6.1
- python3.13
- Dominant language
- Python
- Stars
- 249
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene-pydantic
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
graphql-python/graphene-pydantic#111 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphene-pydantic#107 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
graphql-python/graphene-pydantic#104 · 2 comments · 3 reactions ·
All issues in graphql-python/graphene-pydantic
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
qgis/QGIS-Plugins-Website#459 ·
-
bug severity:medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
bot-found bug priority: P3
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
madenvel/KalinkaPlayer#179 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ls1intum/edutelligence#1098 ·
Maintainers usually reply within 1 day