#23547 closed Bug (worksforme)
BooleanField that is required and have value False always will raise ValidationError — at Version 1
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 (last modified by )
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.
Change History (2)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
by , 10 years ago
Attachment: | 0001-fix-BooleanField-in-case-when-field-is-required-and-.patch added |
---|
Patch for ticket
Note:
See TracTickets
for help on using tickets.
I think your complaint is the same as #23130. If not, could you please reopen with a proposed patch?