graphql-python / graphql-python/graphql-core-legacy
Query execution hangs forever when BaseException is thrown
- Lenguaje dominante
- Python
- Estrellas
- 371
- Forks
- 175
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
If BaseExcetion will occur during query execution everything hangs. I've tried different executors, but this doesn't help. I used `SystemExit` in example for brevity. My real situation was pytest-django throwing exception when you try to access database.
## Example code
```python
import graphene
from graphene.test import Client
class CreatePerson(graphene.Mutation):
ok = graphene.Boolean()
def mutate(self, info):
# Throwing sth that derives from BaseExcetion instead of Exception here causes freeze
raise SystemExit
class Mutation(graphene.ObjectType):
create_person = CreatePerson.Field()
schema = graphene.Schema(mutation=Mutation)
Client(schema).execute('''
mutation{
createPerson{
ok
}
}
''')
```
My debugger shows that it's freezed on this line. Inside `get` promise calls `wait()` and waits forever.
https://github.com/graphql-python/graphql-core/blob/master/graphql/execution/executor.py#L147
Full traceback
```
File "/home/bond/.PyCharm2018.3/config/scratches/scratch_4.py", line 26, in
''')
File "python3.7/site-packages/graphene/test/__init__.py", line 40, in execute
executed = self.schema.execute(*args, **dict(self.execute_options, **kwargs))
File "python3.7/site-packages/graphene/types/schema.py", line 102, in execute
return graphql(self, *args, **kwargs)
File "python3.7/site-packages/graphql/graphql.py", line 44, in graphql
return execute_graphql(*args, **kwargs)
File "python3.7/site-packages/graphql/graphql.py", line 70, in execute_graphql
**execute_options
File "python3.7/site-packages/graphql/backend/core.py", line 34, in execute_and_validate
return execute(schema, document_ast, *args, **kwargs)
File "python3.7/site-packages/graphql/execution/executor.py", line 147, in execute
return promise.get()
File "python3.7/site-packages/promise/promise.py", line 509, in get
self._wait(timeout or DEFAULT_TIMEOUT)
File "python3.7/site-packages/promise/promise.py", line 504, in _wait
self.wait(self, timeout)
```
## Solution
Looks like it should be caught here:
https://github.com/graphql-python/graphql-core/blob/master/graphql/execution/executors/utils.py#L20
https://github.com/graphql-python/graphql-core/blob/master/graphql/execution/executor.py#L448
Am I right?
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Reproduce la mutación de Graphene proporcionada con SystemExit y sigue la espera en promise.Promise.get(). Lee graphql/execution/executors/utils.py en la línea 20 y graphql/execution/executor.py alrededor de la línea 448; después, verifica que una BaseException durante la ejecución ya no deje la consulta bloqueada y que el comportamiento resultante esté cubierto por una prueba de regresión adecuada.
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
- 50/100