NullBooleanField does not clean data correctly when widget=forms.HiddenInput
|Reported by:||ElliottM||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Consider the following snippet of a forms.py file:
class TestForm(forms.Form): null_bool=forms.NullBooleanField(widget=forms.HiddenInput, initial=True)
In django.newforms.widgets, the NullBooleanSelect widget normalizes all the input to either True, False, or None. Up until now, the nullBooleanField.clean() method has expected the input to be in one of these three forms.
However, when a HiddenInput widget is used, that normalization is bypassed, and the NullBooleanfield.clean() method receives a string. In the case I meantioned above, the string would be 'True'. In the (non-null) BooleanField.clean() method, specific tests are done for this, but they're not done in the NullBooleanField.clean() method, and I believe they should be.
A patch is included, with tests.
http://code.djangoproject.com/browser/django/trunk/django/newforms/widgets.py#L226 - NullBooleanSelect widget
http://code.djangoproject.com/browser/django/trunk/django/newforms/fields.py#L560 - Booleanfield field, with the NullBooleanfield defined right below.
Change History (10)
comment:3 Changed 9 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Ready for checkin → Accepted|