Boolean field default value is not applied when request is made using form data #9149
Unanswered
Gomes117
asked this question in
Potential Issue
Replies: 0 comments
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.
-
Minimum code for reproduction:
I would expect that with this code when I send an empty POST I will get an instance of Test with
name = Bob
andis_person = True
. If the request is JSON encoded it works as expected, but if I send it as multipart/form-data only name is set correctly, is_person is set to False.After some debugging I tracked it to Field.get_value() specifically line 427
return self.default_empty_html
. In the case of CharFieldempty
will be returned which will then lead to the default value being used. But for a BooleanField default_empty_html isFalse
which will be set as value and the default value won't be used.I feel like defaults should work the same regardless what type of field is used or what kind of request was made.
Beta Was this translation helpful? Give feedback.
All reactions