Opened 9 years ago

Closed 9 years ago

#5104 closed (fixed)

CheckboxInput should return False if not found

Reported by: Chris Beaven Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This is the crux of the problem people are having with BooleanField. A CheckboxInput widget will only ever return something if it's checked. So if it isn't in cleaned_data then it should be assumed False, not None.

Attachments (3)

checkboxinput.patch (712 bytes) - added by Chris Beaven 9 years ago.
checkboxinput.2.patch (2.6 KB) - added by Chris Beaven 9 years ago.
checkboxinput.3.patch (2.6 KB) - added by Chris Beaven 9 years ago.
clarified the test behaviour

Download all attachments as: .zip

Change History (14)

Changed 9 years ago by Chris Beaven

Attachment: checkboxinput.patch added

comment:1 Changed 9 years ago by Chris Beaven

Has patch: set

comment:2 Changed 9 years ago by Chris Beaven

Needs tests: set
Patch needs improvement: set

Oops, that's not the right patch yet...

Changed 9 years ago by Chris Beaven

Attachment: checkboxinput.2.patch added

comment:3 Changed 9 years ago by Chris Beaven

Needs tests: unset
Patch needs improvement: unset
Summary: CheckboxInput should only return True or FalseCheckboxInput should return False if not found

There, that's better.

I also changed the documentation to get rid of the "No validation" messages because they are confusing. They really mean "No further validation" because the Field validation still applies.

Changed 9 years ago by Chris Beaven

Attachment: checkboxinput.3.patch added

clarified the test behaviour

comment:4 Changed 9 years ago by Chris Beaven

This should be mentioned on http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges because some people could be (probably are) relying on the current behaviour of BooleanField (with default widget) raising a ValidationError if the key doesn't exist.

Note: This is still possible to check for, you just have to do it in a clean_* method.

comment:5 Changed 9 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedReady for checkin

comment:6 Changed 9 years ago by Philippe Raoult

#4480 is a duplicate of this one, closed because we have a good patch here.

comment:7 Changed 9 years ago by Philippe Raoult

same for #5291

comment:8 Changed 9 years ago by James Bennett

Closing #3130 in favor of getting the BooleanField/Checkbox/etc. issues worked out all in one ticket -- this one -- instead of spread out.

comment:9 Changed 9 years ago by Malcolm Tredinnick

Okay, I like the approach Chris is taking here and I'm going to commit a small variation on this patch (predominantly, including some more documentation clarifications). I'm not going to remove the "validates nothing" lines in the third patch, since explicitly including them makes it clear we haven't just forgotten to list the validation conditions.

I agree that this will make the natural behaviour clearer for people and I think this should put the issue to rest.

I'm not going to change the current default for BooleanField subclasses to make it required=False because it's not possible to make that sort of change and break existing code, so people writing BooleanField() at the moment will have their validation conditions weakened and might not notice it (we try to make all backwards incompatible changes fatal if you don't notice them). It simply isn't that hard to type required=False to make that risk necessary. A little annoying for some people; hardly fatal, though.

comment:10 Changed 9 years ago by Malcolm Tredinnick

(In [6564]) Updated the new default value for BooleanFields, clarified the behaviour of
'required' for those fields and updated the examples to use required=False so
that people get the hint. Refs #5104.

comment:11 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

[6563] contained the main code changes, but didn't seem to update this ticket automatically.

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