Merge pull request #6197 from jbradberry/choice-field-metadata

Show API choice field metadata more correctly for null vs ''

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-03-06 15:30:21 +00:00 committed by GitHub
commit 7a3ece7fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,8 +101,10 @@ class Metadata(metadata.SimpleMetadata):
(choice_value, choice_name) for choice_value, choice_name in field.choices.items()
]
if not any(choice in ('', None) for choice, _ in choices):
if field.allow_blank or (field.allow_null and not isinstance(field, ChoiceNullField)):
if field.allow_blank:
choices = [("", "---------")] + choices
if field.allow_null and not isinstance(field, ChoiceNullField):
choices = [(None, "---------")] + choices
field_info['choices'] = choices
# Indicate if a field is write-only.