From b4bcfb35316a4973e6184211867a1248b9fe8feb Mon Sep 17 00:00:00 2001 From: Chang Wang <743976+cheapsteak@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:54:03 -0500 Subject: [PATCH] Preserve the suppressed context of an original error GraphQLError copied the context of an original error but not its __suppress_context__ flag, so an error raised "from None" got its hidden context back when it was wrapped, e.g. by located_error. Fixes #319 Claude-Session: https://claude.ai/code/session_01R8Hmf6XiRffNRSfDMNSFjh --- src/graphql/error/graphql_error.py | 1 + tests/error/test_graphql_error.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/graphql/error/graphql_error.py b/src/graphql/error/graphql_error.py index 668aec11..e346e26b 100644 --- a/src/graphql/error/graphql_error.py +++ b/src/graphql/error/graphql_error.py @@ -314,6 +314,7 @@ def __init__( self.__cause__ = original_error.__cause__ elif original_error.__context__: self.__context__ = original_error.__context__ + self.__suppress_context__ = original_error.__suppress_context__ if extensions is None and underlying_error is not None: original_extensions = getattr(underlying_error, "extensions", None) diff --git a/tests/error/test_graphql_error.py b/tests/error/test_graphql_error.py index 7ff14ff6..28032aaf 100644 --- a/tests/error/test_graphql_error.py +++ b/tests/error/test_graphql_error.py @@ -119,6 +119,19 @@ def passes_the_context_of_an_original_error(): e = GraphQLError("msg", original_error=original) assert e.__context__ is context + def passes_the_suppressed_context_of_an_original_error(): + context = ValueError("hidden") + try: + raise context + except ValueError: + try: + raise RuntimeError("effect") from None + except RuntimeError as runtime_error: + original = runtime_error + e = GraphQLError("msg", original_error=original) + assert e.__context__ is context + assert e.__suppress_context__ is True + def passes_the_cause_of_an_original_error(): cause = ValueError("cause") try: