-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Choices and blank=True #135
Comments
oh thats a tricky one. you are absolutely right about the possible duplication. on the other hand it is a valid input. we have to investigate how to solve that in the least invasive way. |
sry that commit is unrelated. typed the wrong number |
@jayvdb not sure if you were notified of the mention in the PR. would be awesome if you could check out the solution proposal. |
add enum postprocessing handling of blank and null #135
I'm not sure if this is related, but when using CharField choices and blank=True, the '' (which is valid to set it empty) does not come up in the Enum that is created. @tfranzel Do you have any suggestion on how to circumvent this? |
@gabn88 please re-check. this is heavily tested and should work, if It will however not be part of the enum, as it belongs to the field and not the enum itself. You might use that enum with AND without the blank, and thus is has to be combined: drf-spectacular/tests/test_postprocessing.yml Lines 55 to 60 in aeca119
this will be performed for model |
Describe the bug
When there is a charfield with choices, and
blank=True
, the empty string (''
) is a valid value, unrelated to the field being required or not, or nullable or not.However drf-spectacular creates an enum of the choices without an option for the empty string.
To Reproduce
django-oscar-api UserAddressSerializer, BillingAddressSerializer, ShippingAddressSerializer, all include a
title
that has a choices of Mr, Mrs, Dr, etc, andblank=True
Expected behavior
The enum needs to include the empty string, or some other schema structure that allows the empty string.
IMO it would be preferrable that the enum in components doesnt include the empty string, as this would mean two fields using the same choices but different
blank
values would require two enums. And having two enums would result in more clashes, component renames, and those enum names are now appearing in peoples ENUM_NAME_OVERRIDES .The text was updated successfully, but these errors were encountered: