From fec4ad81df42f77a1363caf2e5629600318ee915 Mon Sep 17 00:00:00 2001 From: Hassad Date: Fri, 20 Mar 2026 00:46:44 +0100 Subject: [PATCH] Use equality instead of identity for enum value comparison Fixes #1524. --- graphene/types/enum.py | 4 +++- graphene/types/tests/test_enum.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/graphene/types/enum.py b/graphene/types/enum.py index bc61cd4c..ab398f92 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -9,7 +9,9 @@ def eq_enum(self, other): if isinstance(other, self.__class__): return self is other - return self.value is other + if isinstance(other, PyEnum): + return NotImplemented + return self.value == other def hash_enum(self): diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index e6fce66c..a14e883d 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -613,3 +613,15 @@ def resolve_color(_, info): results = schema.execute("query { color }") assert not results.errors assert results.data["color"] == RGB.description.name + + +def test_enum_value_equality(): + class Kind(Enum): + FAVORABLE = "favorable" + UNFAVORABLE = "unfavorable" + + # non-interned string to avoid identity matching + val = "".join(["favor", "able"]) + assert Kind.FAVORABLE == val + assert Kind.FAVORABLE == "favorable" + assert Kind.FAVORABLE != "unfavorable"