Opened 10 years ago

Last modified 4 years ago

#23547 closed Bug

BooleanField that is required and have value False always will raise ValidationError — at Initial Version

Reported by: Lagovas Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords: Form BooleanField
Cc: Lagovas Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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_messagesrequired, 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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top