graphql-python / graphql-python/graphene

[Documentation] Exception thrown with code copied from documentation

Abierto
#1,240 1 comentario 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

**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']}"
```

Guía de contribución

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

Línea de trabajo

Comienza con la sección "ObjectType -> Quick Example" de la página enlazada de documentación de Graphene y compara su ejemplo de resolver con el comportamiento informado de Graphene 2.1.8. Actualiza el ejemplo para que funcione con el valor de retorno documentado y, después, verifica que el ejemplo completo se ejecute sin la excepción informada.

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

Evaluación

Stack tecnológico
python
Área
documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.