#20982: forms.BooleanField field issue
---------------------------+--------------------------------------
     Reporter:  george.li  |                    Owner:  nobody
         Type:  Bug        |                   Status:  new
    Component:  Forms      |                  Version:  1.7
     Severity:  Normal     |               Resolution:
     Keywords:             |             Triage Stage:  Unreviewed
    Has patch:  1          |      Needs documentation:  0
  Needs tests:  0          |  Patch needs improvement:  0
Easy pickings:  0          |                    UI/UX:  0
---------------------------+--------------------------------------

Comment (by abhillman):

 In django 1.7, this is an issue. There may have been some regression. For
 example:

 {{{
 >>> from django import forms
 >>> forms.BooleanField().clean(True)
 True
 >>> forms.BooleanField().clean(False)
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/Library/Python/2.7/site-packages/django/forms/fields.py", line
 151, in clean
     self.validate(value)
   File "/Library/Python/2.7/site-packages/django/forms/fields.py", line
 735, in validate
     raise ValidationError(self.error_messages['required'],
 code='required')
 ValidationError: [u'This field is required.']
 }}}

 The bug is in the validate method on forms.BooleanField.

 It's code is:

 {{{
     def validate(self, value):
         if not value and self.required:
             raise ValidationError(self.error_messages['required'],
 code='required')
 }}}

 On forms.Field, however, there is a class variable, empty_values that
 should be used. That is, the correct implementation would be:

 {{{
     def validate(self, value):
         if value in self.empty_values and self.required:
             raise ValidationError(self.error_messages['required'],
 code='required')
 }}}

 Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/20982#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.30efed0dd2492c2b7b2cea08fca48aca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to