Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Query execution hangs forever when BaseException is thrown

Open
#225 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Reproduce the provided Graphene mutation with SystemExit and trace the wait in promise.Promise.get(). Read graphql/execution/executors/utils.py at line 20 and graphql/execution/executor.py around line 448, then verify that BaseException during execution no longer leaves the query hanging and that the resulting behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Description

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

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 <module>
  ''')
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?

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphql-core-legacy

All issues in graphql-python/graphql-core-legacy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.