Skip to content

Commit 6a9f820

Browse files
committed
Cast error message to string to handle proxy objects
1 parent b3721c9 commit 6a9f820

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/graphql/error/graphql_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def __str__(self) -> str:
173173
# Lazy import to avoid a cyclic dependency between error and language
174174
from ..language.print_location import print_location, print_source_location
175175

176-
output = [self.message]
176+
output = [str(self.message)]
177177

178178
if self.nodes:
179179
for node in self.nodes:

tests/error/test_graphql_error.py

+24
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,30 @@ def prints_an_error_with_nodes_from_different_sources():
351351
"""
352352
)
353353

354+
def handles_proxy_error_messages():
355+
class ProxyString:
356+
def __init__(self, value):
357+
self.value = value
358+
359+
def __str__(self):
360+
return self.value
361+
362+
error = GraphQLError(ProxyString("Example error")) # type: ignore
363+
364+
assert str(error) == dedent(
365+
"""
366+
Example error
367+
"""
368+
)
369+
370+
error = GraphQLError(ValueError(ProxyString("Example value error"))) # type: ignore # noqa: E501
371+
372+
assert str(error) == dedent(
373+
"""
374+
Example value error
375+
"""
376+
)
377+
354378

355379
def describe_formatted():
356380
def deprecated_formats_an_error_using_format_error():

0 commit comments

Comments
 (0)