[Django] #32622: BooleanField fails when passing False

1 view
Skip to first unread message

Django

unread,
Apr 8, 2021, 10:48:15 AM4/8/21
to django-...@googlegroups.com
#32622: BooleanField fails when passing False
-----------------------------------------+------------------------
Reporter: Tonye Jack | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords: forms,
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
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')
}}}

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

Django

unread,
Apr 8, 2021, 10:48:42 AM4/8/21
to django-...@googlegroups.com
#32622: BooleanField raises ValidationErrors when passing False
-------------------------------+--------------------------------------

Reporter: Tonye Jack | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: forms, | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:1>

Django

unread,
Apr 8, 2021, 10:49:38 AM4/8/21
to django-...@googlegroups.com
#32622: BooleanField raises ValidationErrors when passing False
-------------------------------+--------------------------------------
Reporter: Tonye Jack | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Resolution:

Keywords: forms, | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tonye Jack):

* component: Uncategorized => Forms


--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:2>

Django

unread,
Apr 8, 2021, 11:43:14 AM4/8/21
to django-...@googlegroups.com
#32622: BooleanField raises ValidationErrors when passing False
-------------------------------+--------------------------------------
Reporter: Tonye Jack | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: forms, | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #23547.

--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:3>

Reply all
Reply to author
Forward
0 new messages