Enum equality comparison is inconsistent
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 52/100
Research direction
Start in graphene/types/enum.py at the eq_enum implementation identified in the issue and compare its identity checks with the reported assertion. Verify that equivalent enum values compare consistently with the corresponding string, then confirm the provided reproduction succeeds under the stated Python and Graphene versions.
Written by the indexing model from the issue text.
Description
What is the expected behavior?
I expect the following code to always succeed.
It succeeds in simple scripts. But in a larger code base it fails:
class Kind(graphene.Enum):
INTERMEDIATE_FAVORABLE = "intermediate_favorable"
assert Kind.INTERMEDIATE_FAVORABLE == "intermediate_favorable"
Version
- Version: graphene-3.3
- Platform: cpython 3.11.4, macos ventura 13.5.1 (M1)
Other information
The cause of the bug is here:
https://github.com/graphql-python/graphene/blob/master/graphene/types/enum.py#L12
Equivalent strings are not guaranteed to have the same id.
def eq_enum(self, other):
if isinstance(other, self.__class__):
return self is other
return self.value is other
There's a one-line bug fix:
def eq_enum(self, other):
if isinstance(other, self.__class__):
return self is other
return self.value == other
And I suppose maybe an optimization:
def eq_enum(self, other):
if isinstance(other, self.__class__):
return self is other
return self.value is other or self.value == other
- 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 ·