Opened 17 years ago

Closed 17 years ago

#5104 closed (fixed)

CheckboxInput should return False if not found

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

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 17 years ago.
checkboxinput.2.patch (2.6 KB ) - added by Chris Beaven 17 years ago.
checkboxinput.3.patch (2.6 KB ) - added by Chris Beaven 17 years ago.
clarified the test behaviour

Download all attachments as: .zip

Change History (14)

by Chris Beaven, 17 years ago

Attachment: checkboxinput.patch added

comment:1 by Chris Beaven, 17 years ago

Has patch: set

comment:2 by Chris Beaven, 17 years ago

Needs tests: set
Patch needs improvement: set

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

by Chris Beaven, 17 years ago

Attachment: checkboxinput.2.patch added

comment:3 by Chris Beaven, 17 years ago

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.

by Chris Beaven, 17 years ago

Attachment: checkboxinput.3.patch added

clarified the test behaviour

comment:4 by Chris Beaven, 17 years ago

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 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:6 by Philippe Raoult, 17 years ago

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

comment:7 by Philippe Raoult, 17 years ago

same for #5291

comment:8 by James Bennett, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

(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 by Malcolm Tredinnick, 17 years ago

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