graphql-python / graphql-python/graphene

a field named "items" in InputObjectType occurs TypeError

Abierto
#1,150 2 comentarios 0 reacciones 0 asignados Ver en GitHub
🐛 bug
Lenguaje dominante
Python
Estrellas
8.2k
Forks
818
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Start with the setattr logic in graphene/types/inputobjecttype.py at the linked lines and reproduce the conflict using an InputObjectType field named items. Determine how the field can retain its GraphQL name without breaking json.dumps, then verify the reported example no longer raises the TypeError.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api, backend-api-design
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.