Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Enum equality comparison is inconsistent

Open
#1,524 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
api, backend

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

🐛 bug

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphene

All issues in graphql-python/graphene

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.