Skip to content

Commit b1a9293

Browse files
zbyte64jkimbo
authored andcommitted
fix choices enum: if field can be blank then it isnt required (#714)
1 parent 51adb36 commit b1a9293

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

graphene_django/converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def description(self):
7373
return named_choices_descriptions[self.name]
7474

7575
enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType)
76-
converted = enum(description=field.help_text, required=not field.null)
76+
required = not (field.blank or field.null)
77+
converted = enum(description=field.help_text, required=required)
7778
else:
7879
converted = convert_django_field(field, registry)
7980
if registry is not None:

graphene_django/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Reporter(models.Model):
3838
last_name = models.CharField(max_length=30)
3939
email = models.EmailField()
4040
pets = models.ManyToManyField("self")
41-
a_choice = models.CharField(max_length=30, choices=CHOICES)
41+
a_choice = models.CharField(max_length=30, choices=CHOICES, blank=True)
4242
objects = models.Manager()
4343
doe_objects = DoeReporterManager()
4444

graphene_django/tests/test_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_schema_representation():
171171
lastName: String!
172172
email: String!
173173
pets: [Reporter!]!
174-
aChoice: ReporterAChoice!
174+
aChoice: ReporterAChoice
175175
reporterType: ReporterReporterType
176176
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
177177
}

0 commit comments

Comments
 (0)