Opened 4 years ago
Closed 4 years ago
#32622 closed Uncategorized (duplicate)
BooleanField raises ValidationErrors when passing False
Reported by: | Tonye Jack | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 3.2 |
Severity: | Normal | Keywords: | forms, |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The current django form BooleanField fails when passing False.
class BooleanField(Field): widget = CheckboxInput def to_python(self, value): """Return a Python boolean object.""" # Explicitly check for the string 'False', which is what a hidden field # will submit for False. Also check for '0', since this is what # RadioSelect will provide. Because bool("True") == bool('1') == True, # we don't need to handle that explicitly. if isinstance(value, str) and value.lower() in ('false', '0'): value = False else: value = bool(value) return super().to_python(value) def validate(self, value): if not value and self.required: # <--- Source of the error this should likely use `if value is not None and self.required` raise ValidationError(self.error_messages['required'], code='required')
Change History (3)
comment:1 by , 4 years ago
Summary: | BooleanField fails when passing False → BooleanField raises ValidationErrors when passing False |
---|
comment:2 by , 4 years ago
Component: | Uncategorized → Forms |
---|
comment:3 by , 4 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Duplicate of #23547.