Skip to content

Commit 3a9ffba

Browse files
authored
Merge pull request #23 from morgante/fix_choice_enums
Fix #19 by using choice keys as enum keys, not choice descriptions
2 parents 1bf5d60 + 5ad21f1 commit 3a9ffba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

graphene_django/converter.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from graphene.types.datetime import DateTime
88
from graphene.types.json import JSONString
99
from graphene.utils.str_converters import to_const
10+
from graphql import assert_valid_name
1011

1112
from .compat import (ArrayField, HStoreField, JSONField, RangeField,
1213
RelatedObject, UUIDField)
@@ -17,7 +18,12 @@
1718

1819

1920
def convert_choice_name(name):
20-
return to_const(force_text(name))
21+
name = to_const(force_text(name))
22+
try:
23+
assert_valid_name(name)
24+
except AssertionError:
25+
name = "A_%s" % name
26+
return name
2127

2228

2329
def get_choices(choices):
@@ -26,7 +32,7 @@ def get_choices(choices):
2632
for choice in get_choices(help_text):
2733
yield choice
2834
else:
29-
name = convert_choice_name(help_text)
35+
name = convert_choice_name(value)
3036
description = help_text
3137
yield name, value, description
3238

0 commit comments

Comments
 (0)