graphql-python / graphql-python/graphene-pydantic
ConversionError for constrained pydantic scalars (PositiveFloat, PositiveInt, conint, …) inside Optional or generic containers
- Vorherrschende Sprache
- Python
- Sterne
- 249
- Forks
- 47
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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: ) ```
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
Beitragsleitfaden
Rechercherichtung
Beginne mit find_graphene_type und convert_generic_python_type und verwende das Beispiel Optional[PositiveFloat] aus dem Issue, um den ConversionError zu reproduzieren. Prüfe die Behandlung von Annotated-Typen innerhalb von Unions und generischen Containern; die Aufgabe ist abgeschlossen, wenn eingeschränkte Skalare und benutzerdefinierte Annotated-Aliase ohne Auslösen eines Fehlers konvertiert werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 58/100