AsyncioExecutor produces hard to debug errors
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start in graphql/execution/executors/asyncio.py, especially AsyncioExecutor.execute, and compare its handling with graphql.execution.executor resolve_or_error. Reproduce the sync and async resolver examples from the issue, then verify that async exceptions are logged with their stack traces and that the resulting error retains its stack information.
Written by the indexing model from the issue text.
Description
When an async resolver is raising an exception, this exception is not logged and its stack in lost and never printed. The only "report" is the error carried by the ExecutionResult but we can only access its type and message, not the actual stack trace.
This is different for sync resolvers (even when using the AsyncioExecutor): the exception is printed by graphql.execution.executor resolve_or_error.
Below is an example to illustrate the issue:
from graphql.execution.executors.asyncio import AsyncioExecutor
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLSchema, graphql
def resolve_hello(root, args, context, info):
raise Exception("wololo")
async def resolve_hello_async(root, args, context, info):
raise Exception("wololo")
QueryType = GraphQLObjectType("Query", fields={
"hello": GraphQLField(GraphQLString, resolver=resolve_hello),
"helloAsync": GraphQLField(GraphQLString, resolver=resolve_hello_async),
})
schema = GraphQLSchema(query=QueryType)
print("Sync execution")
result = graphql(schema, '{ hello }', executor=AsyncioExecutor())
# This will log something like:
#
# An error occurred while resolving field Query.hello
# Traceback (most recent call last):
# File ".../site-packages/graphql/execution/executor.py", line 200, in resolve_or_error
# return executor.execute(resolve_fn, source, args, context, info)
# File ".../site-packages/graphql/execution/executors/asyncio.py", line 50, in execute
# result = fn(*args, **kwargs)
# File "test.py", line 11, in resolve_hello
# raise Exception("wololo")
# Exception: wololo
# As a side note, the produced error have a correct stack trace:
print(result.errors[0].stack) # <traceback object at 0x123456789>
print("=" * 10)
print("Async execution")
async_result = graphql(schema, '{ helloAsync }', executor=AsyncioExecutor())
# While producing the same result, it won't log anything, and good luck to know where
# the error comes from.
# This error has None as a stack trace:
print(async_result.errors[0].stack) # None
I am a beginner with python async stuff so I won't send a PR, but as a temporary solution I am replacing the AsyncioExecutor execute method with something like that:
def execute(self, fn, *args, **kwargs):
result = fn(*args, **kwargs)
if isinstance(result, Future) or iscoroutine(result):
async def hop():
try:
awaited_result = await result
except Exception as e:
logger.exception("Exception in %s", fn)
raise
return awaited_result
future = ensure_future(hop(), loop=self.loop)
# future = ensure_future(result, loop=self.loop)
self.futures.append(future)
return Promise.resolve(future)
return result
EDIT: I am using graphene 1.4 and graphql 1.1
- Dominant language
- Python
- Stars
- 371
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphql-core-legacy
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Quiver source Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
graphql-python/graphql-core-legacy#286 · 3 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphql-core-legacy#280 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in graphql-python/graphql-core-legacy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·