Opened 6 years ago

Closed 6 years ago

#18303 closed Bug (invalid)

Wrong comparison in render method of CheckboxInput class.

Reported by: blind Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In line 511 of django.forms.widget, inside the 'render' method of CheckboxInput class, you can see this comparison:

if not (value is True or value is False or value is None or value == ''):

Because in Python the 'is' keyword tests object identity, if value is an object which is emulating a bool type, the comparison wont work.

I think, it should be:

if not (value == True or value == False or value == None or value == ''):

What do you think?

Attachments (1) (33.8 KB) - added by blind 6 years ago.

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by blind

Attachment: added


comment:1 Changed 6 years ago by Anssi Kääriäinen

Resolution: invalid
Status: newclosed

Doesn't work: 0 == False -> True, 0 is False -> False. The current code relies on this, 0 is wanted as value. Closing this as invalid. The code might use some more comments at least, and if you think you have some backwards compatible solution you want to present, feel free to reopen this ticket.

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