Django

Code

Ticket #5563 (closed: fixed)

Opened 2 years ago

Last modified 3 months ago

BooleanField should raise an error if null=True

Reported by: shaunc <shaun@cuttshome.net> Assigned to: SamBull
Milestone: 1.1 Component: Serialization
Version: SVN Keywords:
Cc: shaun@cuttshome.net, david Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

django.db.models.fields.BooleanField?.to_python raises an error on "None" input, but this is valid if null=True for the field.

Attachments

booleanfield-to-python-can-be-none.patch (0.5 kB) - added by shaunc <shaun@cuttshome.net> on 09/21/07 03:02:51.
(patch to fix django.db.models.fields.init.py
boolean_no_null_validation.patch (3.2 kB) - added by SamBull on 03/29/09 23:33:00.
patch to raise a validation error for BooleanField?(null=True)

Change History

09/21/07 03:02:51 changed by shaunc <shaun@cuttshome.net>

  • attachment booleanfield-to-python-can-be-none.patch added.

(patch to fix django.db.models.fields.init.py

09/21/07 03:03:18 changed by shaunc <shaun@cuttshome.net>

  • cc set to shaun@cuttshome.net.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

09/21/07 19:26:10 changed by anonymous

Isn't this what NullBooleanField? is for?

09/21/07 21:35:07 changed by shaunc <shaun@cuttshome.net>

  • has_patch deleted.
  • summary changed from BooleanField can be None if null=True to BooleanField should raise an error if null=True.

um... well, how about that: I never noticed NullBooleanField? before. I'd close this, but I'll leave it up to others to decide if the following should be done so others don't go astray:

1) doc for BooleanField? should mention that one should use NullBooleanField? rather than null=True. 2) passing null=True to BooleanField? init should cause an exception to be raised (whose error text says: "use NullBooleanField?")

09/22/07 00:02:24 changed by ubernostrum

  • stage changed from Unreviewed to Design decision needed.

There's been a lot of discussion lately about BooleanField and NullBooleanField, and it's debatable whether NullBooleanField is really appropriate for this use case.

12/17/07 15:47:42 changed by brosner

Marked #6229 as a duplicate.

01/01/09 22:25:56 changed by david

  • cc changed from shaun@cuttshome.net to shaun@cuttshome.net, david.
  • has_patch set to 1.

I can confirm, it breaks json deserialization with None values.

== True from the patch is probably useless?

03/18/09 10:09:29 changed by jacob

  • stage changed from Design decision needed to Accepted.
  • milestone set to 1.1.

We either need to fix this or raise a validation warning about BooleanField(null=True).

03/29/09 21:20:47 changed by SamBull

  • owner changed from nobody to SamBull.
  • status changed from new to assigned.

03/29/09 23:33:00 changed by SamBull

  • attachment boolean_no_null_validation.patch added.

patch to raise a validation error for BooleanField?(null=True)

03/29/09 23:38:48 changed by SamBull

I've added a new patch. This adds a model validation check that raises an error if null=True is set within a BooleanField.

I also added a test for the new behaviour and updated a serialization test that was failing after the change.

04/07/09 15:26:42 changed by jacob

  • stage changed from Accepted to Design decision needed.

04/09/09 10:09:36 changed by jacob

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

(In [10456]) Fixed #5563: BooleanField(null=True) now raises a validation warning telling users to use NullBooleanField instead. Thanks, SamBull?.


Add/Change #5563 (BooleanField should raise an error if null=True)




Change Properties
Action