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

Exception traceback disappears when running middleware

Ouverte
#208 3 commentaires 6 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
372
Forks
175
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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`.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans graphql/execution/executor.py vers la ligne 529 et suivez le chemin du rejet de la promesse jusqu’à complete_value_catching_error. Reproduisez l’exemple fourni de schéma et de middleware, en comparant l’exécution avec et sans middleware. Le travail est terminé lorsque le cas avec middleware conserve et journalise la traceback du resolver au lieu de ne contenir que GraphQLLocatedError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend-api-design
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.