ModelSerializer: Using a class that does not inherit from ChoiceField strips allow_blank #8997
Unanswered
amhn
asked this question in
Potential Issue
Replies: 1 comment 3 replies
-
what issue is it causing actually? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While trying to improve schema generation for netbox, I stumbled on something:
I wanted to change the default serializer for fields with choices, so in a subclass of ModelSerializer I set serializer_choice_field to
netbox.api.fields.ChoiceField
which is not a subclass ofrest_framework.fields.ChoiceField
.Everything looked fine except for fields with
allow_blank=True
. This was omitted from the schema.I think this is because of the following check:
django-rest-framework/rest_framework/serializers.py
Lines 1296 to 1298 in e2a4559
I think either this check should be changed to use
self.serializer_choice_field
instead ofChoiceField
or moved before Line 1272:django-rest-framework/rest_framework/serializers.py
Lines 1272 to 1275 in e2a4559
Did I miss something?
Beta Was this translation helpful? Give feedback.
All reactions