Code

Opened 2 years ago

Closed 2 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

Description

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)

widgets.py (33.8 KB) - added by blind 2 years ago.
patch

Download all attachments as: .zip

Change History (2)

Changed 2 years ago by blind

patch

comment:1 Changed 2 years ago by akaariai

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

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.