Django

Code

Ticket #5104 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

CheckboxInput should return False if not found

Reported by: SmileyChris Assigned to: nobody
Milestone: Component: Forms
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

checkboxinput.patch (0.7 kB) - added by SmileyChris on 08/06/07 16:13:48.
checkboxinput.2.patch (2.6 kB) - added by SmileyChris on 08/06/07 16:34:57.
checkboxinput.3.patch (2.6 kB) - added by SmileyChris on 08/06/07 16:40:11.
clarified the test behaviour

Change History

08/06/07 16:13:48 changed by SmileyChris

  • attachment checkboxinput.patch added.

08/06/07 16:14:05 changed by SmileyChris

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

08/06/07 16:19:50 changed by SmileyChris

  • needs_better_patch set to 1.
  • needs_tests set to 1.

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

08/06/07 16:34:57 changed by SmileyChris

  • attachment checkboxinput.2.patch added.

08/06/07 16:36:47 changed by SmileyChris

  • needs_better_patch deleted.
  • needs_tests deleted.
  • summary changed from CheckboxInput should only return True or False to CheckboxInput 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.

08/06/07 16:40:11 changed by SmileyChris

  • attachment checkboxinput.3.patch added.

clarified the test behaviour

08/06/07 17:05:08 changed by SmileyChris

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.

08/11/07 02:24:28 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Ready for checkin.

09/14/07 13:06:06 changed by PhiR

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

09/15/07 15:44:05 changed by PhiR

same for #5291

09/16/07 16:46:40 changed by ubernostrum

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

10/20/07 07:13:04 changed by mtredinnick

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.

10/20/07 07:21:17 changed by mtredinnick

(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.

10/20/07 07:22:42 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #5104 (CheckboxInput should return False if not found)




Change Properties
Action