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
BooleanField required argument is ignored #1004
Comments
Seems valid. First obvious step would be for someone to write a failing test case for this and submit it as a pull request. |
Failing test in a pull request: #1044 |
Note: The browsable API works fine, without the default being set.
Fixed by 28ff6fb. |
I think this issue still exist. Here's my code. I'm using djangorestframework==3.4.6 in models.pyx = models.BooleanField() in serializers.pyx = serializers.BooleanField(required=True) POST body (JSON){ Then I got 500 error:IntegrityError: (1048, "Column 'x' cannot be null") What I expectshould return an 400 error saying "x is required". ==== Update ==== Sorry @xordoquy for bothering you :P |
This is covered by a test so it'll likely be something on your side. A test case highlighting the issue will be required to go further. |
I have this problem too. (DRF 3.7.3) |
As said in previous comment, it's already covered and working with a test case in DRF test suite. So either your code is doing something wrong either there's an issue in DRF. In the later case we'll need a test case we can reproduce to highlight the issue. |
OK, but I just tried this in the shell and I get the expected result:
So there must be something else going on. @thakryptex Can you add a test case to the test suite that recreates your issue? If we have a failing PR we can see exactly what's going on, and fix it. |
My bet, it's because data are sent through forms and the outcome would be the one expected. |
@thakryptex yes it is because it's forms and it's a usage question. |
Ok, let's read: Forms BooleanField
So, everything is fine and looks like it supposed to be. (I also checked BooleanField in Models) |
It looks like BooleanFields get a default of False and because of that they can't be required. So doing this has no effect:
I'm pretty sure the problem is this in
rest_framework/fields.py
BooleanField definition:The text was updated successfully, but these errors were encountered: