Enum.from_enum() fails with Django IntegerChoices
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Parti da graphene.Enum.from_enum() e dal comportamento di GrapheneEnumType generato, usando l’esempio fornito di Django IntegerChoices per riprodurre il problema. Confronta la gestione di TextChoices con quella di IntegerChoices; il lavoro è completato quando valori come 1, 2 e 9 possono essere rappresentati dall’enum Graphene generato senza l’errore segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Current Behavior
I am working in a Django Python codebase that has a GraphQL schema. A lot of TextChoices are used in our GraphQL schema and, to properly represent these we use the provided graphene.Enum.from_enum() function.
This same approach doesn't seem to work with Django's IntegerChoices. It seems when graphene generates a GrapheneEnumType, the values are created with the IntegerChoices member names. This makes it so the IntegerChoices value cannot be represented with the generated GrapheneEnumType.
This results in an error like the following:
"Enum 'Status' cannot represent value: 2"
Expected Behavior
A value from a Django IntegerChoices object is usable to get the appropriate GrapheneEnumType value name.
motivation
To allow for graphene.Enum.from_enum() to be usable by Django's IntegerChoices class.
Environment
- Graphene Version: 3.3
- Graphene Django Version: 3.2.0
- Graphene Version: 3.3
- Django Version: 4.1.12
- Python Version: 3.10
Code Example
class Status(models.IntegerChoices):
COMPLETED = 1, "Completed"
IN_PROGRESS = 2, "In progress"
ERRORED = 9, "Errored"
StatusChoices = graphene.Enum.from_enum(Status)
class Process(graphene.ObjectType):
reference = graphene.String(description="The process reference.")
status = graphene.Field(
StatusChoices,
description="Current process status.",
)
This results in an error like the following:
"Enum 'Status' cannot represent value: 2"
- Lingua principale
- Python
- Stelle
- 8.2k
- Fork
- 818
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql-python/graphene
-
Tutorial mistakes Aperta🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
graphql-python/graphene#1389 · 5 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support Aperta✨ enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
graphql-python/graphene#1601 · 2 commenti ·
-
✨ enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
graphql-python/graphene#1593 ·
Tutte le issue di graphql-python/graphene
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
huggingface/Repo2RLEnv#163 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NousResearch/hermes-agent#121143 ·