mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 09:57:53 +03:00 
			
		
		
		
	Avoid collisions in choices names conversion.
This commit is contained in:
		
							parent
							
								
									4246ceaa85
								
							
						
					
					
						commit
						2c26774c62
					
				| 
						 | 
					@ -27,12 +27,16 @@ def convert_choice_name(name):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_choices(choices):
 | 
					def get_choices(choices):
 | 
				
			||||||
 | 
					    converted_names = []
 | 
				
			||||||
    for value, help_text in choices:
 | 
					    for value, help_text in choices:
 | 
				
			||||||
        if isinstance(help_text, (tuple, list)):
 | 
					        if isinstance(help_text, (tuple, list)):
 | 
				
			||||||
            for choice in get_choices(help_text):
 | 
					            for choice in get_choices(help_text):
 | 
				
			||||||
                yield choice
 | 
					                yield choice
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            name = convert_choice_name(value)
 | 
					            name = convert_choice_name(value)
 | 
				
			||||||
 | 
					            if name in converted_names:
 | 
				
			||||||
 | 
					                name += '_' + str(len(converted_names))
 | 
				
			||||||
 | 
					            converted_names.append(name)
 | 
				
			||||||
            description = help_text
 | 
					            description = help_text
 | 
				
			||||||
            yield name, value, description
 | 
					            yield name, value, description
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,6 +176,21 @@ def test_field_with_choices_gettext():
 | 
				
			||||||
    convert_django_field_with_choices(field)
 | 
					    convert_django_field_with_choices(field)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_field_with_choices_collision():
 | 
				
			||||||
 | 
					    field = models.CharField(help_text='Timezone', choices=(
 | 
				
			||||||
 | 
					        ('Etc/GMT+1', 'Greenwich Mean Time +1'),
 | 
				
			||||||
 | 
					        ('Etc/GMT-1', 'Greenwich Mean Time -1'),
 | 
				
			||||||
 | 
					    ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class CollisionChoicesModel(models.Model):
 | 
				
			||||||
 | 
					        timezone = field
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class Meta:
 | 
				
			||||||
 | 
					            app_label = 'test'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    convert_django_field_with_choices(field)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_should_float_convert_float():
 | 
					def test_should_float_convert_float():
 | 
				
			||||||
    assert_conversion(models.FloatField, graphene.Float)
 | 
					    assert_conversion(models.FloatField, graphene.Float)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user