#23547: BooleanField that is required and have value False always will raise
ValidationError
----------------------------+-------------------------------
     Reporter:  Lagovas     |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.6
     Severity:  Normal      |   Keywords:  Form BooleanField
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+-------------------------------
 class BooleanField(Field):
    def to_python(self, value):
         if isinstance(value, six.string_types) and value.lower() in
 ('false', '0'):
             value = False
         else:
             value = bool(value)
         return super(BooleanField, self).to_python(value)

    def validate(self, value):
         if not value and self.required:
             raise ValidationError(self.error_messages['required'],
 code='required')
 In method "validate" value is "True" or "False" as python object, because
 called after to_python.
 So if value is valid ('0' or 'false') and field is required, will be
 raised ValidationError.
 Anyway value in "validate" will be False if value is not '0' or 'false',
 so method validate should be empty because always is valid.

--
Ticket URL: <https://code.djangoproject.com/ticket/23547>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.8682f2c8c262de694da821749b70cf1a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to