Opened 5 years ago

Closed 5 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: UI/UX:

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 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

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