graphql-python / graphql-python/graphene

a field named "items" in InputObjectType occurs TypeError

Ouverte
#1,150 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
🐛 bug
Langage dominant
Python
Étoiles
8.2k
Forks
818
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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 :)

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par la logique de setattr dans graphene/types/inputobjecttype.py aux lignes indiquées par le lien et reproduisez le conflit avec un champ de InputObjectType nommé items. Déterminez comment le champ peut conserver son nom GraphQL sans perturber json.dumps, puis vérifiez que l’exemple signalé ne lève plus de TypeError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
api, backend-api-design
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.