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

Exception traceback disappears when running middleware

オープン
#208 コメント 3 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
371
フォーク
175
PR マージ指標
30日以内にマージされた PR はありません

説明

Here's a small example that illustrates the issue:

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 "<ipython-input-1-89a125ef67fc>", 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 "<ipython-input-1-89a125ef67fc>", 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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

graphql/execution/executor.py の529行目付近から始め、promise rejection の経路を complete_value_catching_error まで追跡します。提示されたスキーマとミドルウェアの例を再現し、ミドルウェアありとなしで実行を比較します。ミドルウェアありの場合に、GraphQLLocatedError だけでなく resolver の traceback を保持してログに記録できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend-api-design
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。