Skip to content

Commit 2c26774

Browse files
author
Pablo Chinea
committed
Avoid collisions in choices names conversion.
1 parent 4246cea commit 2c26774

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

graphene_django/converter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ def convert_choice_name(name):
2727

2828

2929
def get_choices(choices):
30+
converted_names = []
3031
for value, help_text in choices:
3132
if isinstance(help_text, (tuple, list)):
3233
for choice in get_choices(help_text):
3334
yield choice
3435
else:
3536
name = convert_choice_name(value)
37+
if name in converted_names:
38+
name += '_' + str(len(converted_names))
39+
converted_names.append(name)
3640
description = help_text
3741
yield name, value, description
3842

graphene_django/tests/test_converter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ class Meta:
176176
convert_django_field_with_choices(field)
177177

178178

179+
def test_field_with_choices_collision():
180+
field = models.CharField(help_text='Timezone', choices=(
181+
('Etc/GMT+1', 'Greenwich Mean Time +1'),
182+
('Etc/GMT-1', 'Greenwich Mean Time -1'),
183+
))
184+
185+
class CollisionChoicesModel(models.Model):
186+
timezone = field
187+
188+
class Meta:
189+
app_label = 'test'
190+
191+
convert_django_field_with_choices(field)
192+
193+
179194
def test_should_float_convert_float():
180195
assert_conversion(models.FloatField, graphene.Float)
181196

0 commit comments

Comments
 (0)