graphql-python / graphql-python/graphene

[Documentation] Exception thrown with code copied from documentation

オープン
#1,240 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
🐛 bug
主要言語
Python
スター
8.2k
フォーク
818
PR マージ指標
30日以内にマージされた PR はありません

説明

**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports.

* **What is the current behavior?**
The code listed in ["ObjectType -> Quick Example"](https://docs.graphene-python.org/en/latest/types/objecttypes/#quick-example) throws exceptions.

My code:
```python
from graphene import ObjectType, String, Field, Schema

class Person(ObjectType):
first_name = String()
last_name = String()
full_name = String()

def resolve_full_name(parent, info):
return f"{parent.first_name} {parent.last_name}"

def person_resolver(root, info):
return {
"first_name": "John",
"last_name": "Doe",
}

class Query(ObjectType):
Person = Field(Person, resolver=person_resolver)

schema = Schema(query=Query, auto_camelcase=False)

data = schema.execute(
"""
query{
Person{
first_name
last_name
full_name
}
}
"""
)

print(data)
```

Exception thrown:
```
An error occurred while resolving field Person.full_name
Traceback (most recent call last):
File "C:\Users\keith.vandermeulen\Documents\play\venv\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "C:\Users\keith.vandermeulen\Documents\play\venv\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute
return fn(*args, **kwargs)
File "test.py", line 7, in resolve_full_name
return f"{parent.first_name} {parent.last_name}"
AttributeError: 'dict' object has no attribute 'first_name'
Traceback (most recent call last):
File "C:\Users\keith.vandermeulen\Documents\play\venv\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "C:\Users\keith.vandermeulen\Documents\play\venv\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute
return fn(*args, **kwargs)
File "test.py", line 7, in resolve_full_name
return f"{parent.first_name} {parent.last_name}"
graphql.error.located_error.GraphQLLocatedError: 'dict' object has no attribute 'first_name'

OrderedDict([('errors', [{'message': "'dict' object has no attribute 'first_name'", 'locations': [{'line': 6, 'column': 5}], 'path': ['Person', 'full_name']}]), ('data', OrderedDict([('Person', OrderedDict([('first_name', 'John'), ('last_name', 'Doe'), ('full_name', None)]))]))])
```

* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via
a github repo, https://repl.it or similar.

* **What is the expected behavior?**
The documentation should contain working code.

* **What is the motivation / use case for changing the behavior?**
The documentation first example doesn't work. This seems like a bug...

* **Please tell us about your environment:**

- Version: 2.1.8
- Platform: Windows 10

Here is my `pip list` command from a fresh virtualenv:
```
Package Version
------------- -------
aniso8601 7.0.0
graphene 2.1.8
graphql-core 2.3.2
graphql-relay 2.0.1
pip 20.0.2
promise 2.3
Rx 1.6.1
setuptools 46.0.0
six 1.15.0
wheel 0.34.2
```

* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
Please note that I created a brand new virtualenv with a fresh pip install today to try this out. It seems as though `parent` is actually a dictionary and the resolver works if changed to the following:

```python
def resolve_full_name(parent, info):
return f"{parent['first_name']} {parent['last_name']}"
```

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

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

調査の方向性

リンク先のGrapheneドキュメントページにある「ObjectType -> Quick Example」セクションから始め、そこにあるresolverの例を、報告されているGraphene 2.1.8の動作と比較してください。ドキュメントに記載された戻り値で動作するように例を更新し、その後、完全な例が報告された例外なしで実行されることを確認してください。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

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

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