-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
NullBooleanField returns boolean value False
for empty QueryDict.
#7582
Comments
I observe that https://github.com/encode/django-rest-framework/blob/master/rest_framework/fields.py#L432 is False for the first case (data={}) which raises SkipField here https://github.com/encode/django-rest-framework/blob/master/rest_framework/serializers.py#L476 and True for the second case (data=QueryDict()) which lets set_value to be called here https://github.com/encode/django-rest-framework/blob/master/rest_framework/serializers.py#L486 |
This is likely because If you alter your field definition as A PR with the appropriate test could fix that too. |
That's right, are we sure though that the developers' intentions are for |
Yes that is the expectation. But @xordoquy alternate field definition works well with This does feel like a breaking change though in my opinion. If we didn't have proper CI/CD tests, this won't have been caught. |
We too were caught out by this change. Our CI/CD test noticed the regression and we spent quite a while getting to the bottom of it. |
Just ran across this when upgrading our project to to 3.12.x (from 3.11.x) and also only caught it because of tests. A BooleanField with |
I faced this as well where I was expecting the empty query dict to not insert the boolean seeing that NullBooleanField is deprecated for DRF and django and I didn't actually need the third state (just using it to know whether true or false was explicitly given since default_empty_html otherwise obfuscates that), my solution is to override BooleanField:
use case:
You can add |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
can any of you try #8614 and report back please? seems related to this issue |
Checklist
master
branch of Django REST framework.Steps to reproduce
Create a serializer as below with the test data
Expected behavior
s_dict
ands_qdict
has the same value which isis_active: None
Actual behavior
s_dict
returnsis_active: None
buts_qdict
returnsis_active: False
NullBooleanField
was primarily used to avoiddefault_empty_html
fromBooleanField
. Now that it is merged what is the alternative?The text was updated successfully, but these errors were encountered: