Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enum equality comparison is inconsistent #1524

Open
Labels
@cc-jj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /