graphql-python / graphql-python/graphene
a field named "items" in InputObjectType occurs TypeError
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I was trying to `json.dumps` with all inputs and some inputs had `TypeError` when they have a field named "items" like below.
```py
class ConfigInput(graphene.InputObjectType):
items = graphene.List(lambda: AnotherConfigInput)
...
```
when I try to `json.dumps` with this input, the error looks like
```py
File "/project/venv/lib/python3.7/site-packages/playhouse/mysql_ext.py", line 36, in db_value
return json.dumps(value)
File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
TypeError: attribute of type 'list' is not callable
```
found that [`setattr` in `InputObjectType` class](https://github.com/graphql-python/graphene/blob/master/graphene/types/inputobjecttype.py#L23-L24) overrides field's attr `items` which conflicts with the attribute `items` of `List`.
This is naming conflict, so I just solved it like below
```py
class ConfigInput(graphene.InputObjectType):
_items = graphene.List(lambda: AnotherConfigInput, name='items')
...
```
wonder if there is any good fix from graphene like [this issue](https://github.com/graphql-python/graphene/issues/899)
please let me know if you need more info or examples :)
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
リンク先の行にある graphene/types/inputobjecttype.py の setattr ロジックから始め、items という名前の InputObjectType フィールドを使って競合を再現します。json.dumps を壊さずにフィールドが GraphQL 名を保持できる方法を特定し、報告された例で TypeError が発生しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend-api-design
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100