Opened 15 years ago

Closed 15 years ago

#12160 closed (invalid)

BooleanField clean method fails for false values

Reported by: spatovich@… Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords: BooleanField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a BooleanField is defined as required, calling clean on False values causes ValidationError.

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.forms.fields import *
>>> f = BooleanField()
>>> f
<django.forms.fields.BooleanField object at 0x01EB8A50>
>>> f.clean('0')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python25\lib\site-packages\django\forms\fields.py", line 597, in clean
    raise ValidationError(self.error_messages['required'])
ValidationError: [u'This field is required.']
>>> f.clean(False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python25\lib\site-packages\django\forms\fields.py", line 597, in clean
    raise ValidationError(self.error_messages['required'])
ValidationError: [u'This field is required.']
>>> f.clean(True)
True
>>> f.clean('1')
True
>>>

Change History (1)

comment:1 by Alex Gaynor, 15 years ago

Resolution: invalid
Status: newclosed

This is intentional, see #5957 for discussion of tihs issue.

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