Enum conversion to Graphene Enum fails if Enum name is "type"
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
Comienza con graphene/types/enum.py y el punto de entrada from_enum mostrado en el traceback; después, reproduce el fallo usando el ejemplo vinculado de graphene-bug. Confirma que convertir un enum cuyo nombre es "type" se realiza correctamente sin el TypeError mostrado y añade una prueba de regresión para ese caso.
Escrito por el modelo de indexación a partir del texto del issue.
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?
See title. I've reproduced the bug together with graphene-django, but the actual bug is in graphene itself, so I'm raising the issue here. Example repo is here: https://github.com/matti-lamppu/graphene-bug.
What is the expected behavior?
I can create an enum field with the name type.
What is the motivation/use case for changing the behavior?
My Django models can have fields named type and I can use serializers to describe how mutations work on them (I know this is graphene-django related, but still).
Please tell us about your environment:
- Version: 3.3.0
- Platform: Windows
See the full list of dependencies in the example repo I linked.
Other information
The example repo has a minimal example and explanation of what causes the bug and a possible solution. The traceback is available in the repo as well as below.
Traceback
[30/Aug/2023 09:13:35] "GET / HTTP/1.1" 404 2061
Internal Server Error: /graphql/
Traceback (most recent call last):
File "...\mysite\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\django\views\generic\base.py", line 97, in view
self = cls(**initkwargs)
^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\views.py", line 105, in __init__
schema = graphene_settings.SCHEMA
^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\settings.py", line 123, in __getattr__
val = perform_import(val, attr)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\settings.py", line 62, in perform_import
return import_from_string(val, setting_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\settings.py", line 76, in import_from_string
module = importlib.import_module(module_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Python311\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "...\mysite\foo\schema.py", line 16, in
class FooMutation(SerializerMutation):
File "...\mysite\venv\Lib\site-packages\graphene\types\objecttype.py", line 30, in __new__
base_cls = super().__new__(
^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene\utils\subclass_with_meta.py", line 46, in __init_subclass__
super_class.__init_subclass_with_meta__(**options)
File "...\mysite\venv\Lib\site-packages\graphene_django\rest_framework\mutation.py", line 102, in __init_subclass_with_meta__
output_fields = fields_for_serializer(
^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\rest_framework\mutation.py", line 52, in fields_for_serializer
fields[name] = convert_serializer_field(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\rest_framework\serializer_converter.py", line 31, in convert_serializer_field
graphql_type = get_graphene_type_from_serializer_field(field)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Lib\functools.py", line 909, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\rest_framework\serializer_converter.py", line 163, in convert_serializer_field_to_enum
return convert_choices_to_named_enum_with_descriptions(name, field.choices)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene_django\converter.py", line 101, in convert_choices_to_named_enum_with_descriptions
return_type = Enum(
^^^^^
File "...\mysite\venv\Lib\site-packages\graphene\types\enum.py", line 53, in __call__
return cls.from_enum(
^^^^^^^^^^^^^^
File "...\mysite\venv\Lib\site-packages\graphene\types\enum.py", line 74, in from_enum
meta_class = type("Meta", (object,), meta_dict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EnumType.__call__() takes from 2 to 3 positional arguments but 4 were given
[30/Aug/2023 09:13:39] "GET /graphql/ HTTP/1.1" 500 186631
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 822
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphql-python/graphene
-
Tutorial mistakesAbierto🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
graphql-python/graphene#1389 · 5 comentarios · 2 reacciones ·
-
✨ enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
graphql-python/graphene#1609 ·
-
Support OneOf input object typesAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 supportAbierto✨ enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
graphql-python/graphene#1601 · 2 comentarios ·
-
✨ enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
graphql-python/graphene#1600 ·
Todos los issues de graphql-python/graphene
Issues similares
-
Path subtraction removes repeated suffix characters instead of one suffixPosiblemente ocupada @Gwerdonatus la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
joke2k/django-environ#671 ·
-
good first issue help wanted windows
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
-
test_pgbouncer deploys the server under test from Charmhub instead of the local build (track/1.31)Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
canonical/temporal-k8s-operator#195 · 1 comentario ·
Los mantenedores suelen responder en 4 días
-
`burr` fails to start when the Python path has a space in itPosiblemente ocupada @enekoreto la tomó hoy. Abiertostatus/needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 5 días
-
device support request
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
zigpy/zha-device-handlers#5461 ·
Los mantenedores suelen responder en 4 días