Enum.from_enum() fails with Django IntegerChoices
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start at graphene.Enum.from_enum() and the generated GrapheneEnumType behavior, using the provided Django IntegerChoices example to reproduce the failure. Compare the handling of TextChoices with IntegerChoices; the work is done when values such as 1, 2, and 9 can be represented by the generated Graphene enum without the reported error.
Written by the indexing model from the issue text.
Description
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"
- Dominant language
- Python
- Stars
- 8.2k
- Forks
- 818
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
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
-
Tutorial mistakes Open🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
graphql-python/graphene#1389 · 5 comments · 2 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support Open✨ enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
graphql-python/graphene#1601 · 2 comments ·
-
✨ enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
graphql-python/graphene#1593 ·
All issues in graphql-python/graphene
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·