From 399b62fe0c513eaf476b659326d2f9489a06a1ab Mon Sep 17 00:00:00 2001 From: Jason Kraus Date: Fri, 19 Jul 2019 11:37:18 -0700 Subject: [PATCH] fix choices enum: if field can be blank then it isnt required --- graphene_django/converter.py | 3 ++- graphene_django/tests/models.py | 2 +- graphene_django/tests/test_types.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/graphene_django/converter.py b/graphene_django/converter.py index 64bf341a9..b1e27fc70 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -73,7 +73,8 @@ def description(self): return named_choices_descriptions[self.name] enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType) - converted = enum(description=field.help_text, required=not field.null) + required = not (field.blank or field.null) + converted = enum(description=field.help_text, required=required) else: converted = convert_django_field(field, registry) if registry is not None: diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index b4eb3ce8a..14a8367d6 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -38,7 +38,7 @@ class Reporter(models.Model): last_name = models.CharField(max_length=30) email = models.EmailField() pets = models.ManyToManyField("self") - a_choice = models.CharField(max_length=30, choices=CHOICES) + a_choice = models.CharField(max_length=30, choices=CHOICES, blank=True) objects = models.Manager() doe_objects = DoeReporterManager() diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 6cbaae0bb..8b84fcada 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -171,7 +171,7 @@ def test_schema_representation(): lastName: String! email: String! pets: [Reporter!]! - aChoice: ReporterAChoice! + aChoice: ReporterAChoice reporterType: ReporterReporterType articles(before: String, after: String, first: Int, last: Int): ArticleConnection }