Skip to content

convert_django_field_with_choices appears not to work #33

Closed
@crucialfelix

Description

@crucialfelix

Hi. Given:

RATING_CHOICES = (
    (0, ''),   # or (0 'none')
    (1, '*'), 
    (2, '**'),
    (3, '***'), 
    (4, '****'), 
    (5, '*****')
)

class Note(models.Model):

    rating = models.IntegerField(choices=RATING_CHOICES, blank=True, default=0)

# ...
class NoteNode(DjangoObjectType):

    class Meta:
        model = Note
        interfaces = (relay.Node,)

# fails when loading the schema
from mattermind.schema import schema

I get a failure to auto-create:

choices [(0, 0, ''), (1, 1, '*'), (2, 2, '**'), (3, 3, '***'), (4, 4, '****'), (5, 5, '*****')]
named_choices [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]
named_choices_descriptions {0: '', 1: '*', 2: '**', 3: '***', 4: '****', 5: '*****'}
Traceback (most recent call last):
  File "try_schema.py", line 13, in <module>
    def convert_choice_name(name):
  File "/Users/crucial/miniconda3/envs/mattermind/lib/python3.5/site-packages/graphene/types/enum.py", line 41, in __call__
    return cls.from_enum(PyEnum(*args, **kwargs), description=description)
  File "/Users/crucial/miniconda3/envs/mattermind/lib/python3.5/enum.py", line 243, in __call__
    return cls._create_(value, names, module=module, qualname=qualname, type=type, start=start)
  File "/Users/crucial/miniconda3/envs/mattermind/lib/python3.5/enum.py", line 342, in _create_
    classdict[member_name] = member_value
  File "/Users/crucial/miniconda3/envs/mattermind/lib/python3.5/enum.py", line 60, in __setitem__
    if _is_sunder(key):
  File "/Users/crucial/miniconda3/envs/mattermind/lib/python3.5/enum.py", line 26, in _is_sunder
    return (name[0] == name[-1] == '_' and
TypeError: 'int' object is not subscriptable

The debug statements are posted for lines 45-47 from here:

https://github.com/graphql-python/graphene-django/blob/master/graphene_django/converter.py#L40

named_choices looks wrong.

graphene
graphene-django
django_graphiql
graphql-core
django==1.9
django-filter==0.11.0

python 3.5

Awesome project, everything else has been very simple so far, thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions