graphql-python / graphql-python/graphql-core-legacy

Exception traceback disappears when running middleware

Abierto
#208 3 comentarios 6 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
372
Forks
175
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Here's a small example that illustrates the issue:

```python
import logging

import graphene

logging.basicConfig()

class Query(graphene.ObjectType):
hello = graphene.String()

def resolve_hello(self, info):
raise Exception('error')
return 'Hello'

schema = graphene.Schema(query=Query)

def middleware(next, root, info, **kwargs):
return next(root, info, **kwargs)
```

If we execute a query without any middleware, we get the traceback:

```
In [3]: schema.execute('{ hello }')
ERROR:graphql.execution.executor:An error occurred while resolving field Query.hello
Traceback (most recent call last):
File "/home/felipe/.local/share/virtualenvs/graphene-hello-viSdSxbU/local/lib/python2.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "/home/felipe/.local/share/virtualenvs/graphene-hello-viSdSxbU/local/lib/python2.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
return fn(*args, **kwargs)
File "", line 12, in resolve_hello
raise Exception('error')
Exception: error
ERROR:graphql.execution.utils:Traceback (most recent call last):
File "/home/felipe/.local/share/virtualenvs/graphene-hello-viSdSxbU/local/lib/python2.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "/home/felipe/.local/share/virtualenvs/graphene-hello-viSdSxbU/local/lib/python2.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
return fn(*args, **kwargs)
File "", line 12, in resolve_hello
raise Exception('error')
GraphQLLocatedError: error
```

But if we run it with the middleware, we get very little information:

```
In [4]: schema.execute('{ hello }', middleware=[middleware])
ERROR:graphql.execution.utils:GraphQLLocatedError: error
```

While investigating the issue, it looks like the point the traceback gets lost is around https://github.com/graphql-python/graphql-core/blob/master/graphql/execution/executor.py#L529. The promise gets rejected because of the exception, and then the `is_reject` handler returns *another* promise that gets immediately rejected. This new error has no traceback, so it doesn't get logged when it's caught inside `complete_value_catching_error`.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en graphql/execution/executor.py alrededor de la línea 529 y sigue la ruta de rechazo de la promesa hasta complete_value_catching_error. Reproduce el ejemplo proporcionado de esquema y middleware, comparando la ejecución con y sin middleware. Se considera terminado cuando el caso con middleware conserva y registra el traceback del resolver, en lugar de mostrar únicamente GraphQLLocatedError.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend-api-design
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.