Opened 17 years ago

Closed 16 years ago

Last modified 13 years ago

#5563 closed (fixed)

BooleanField should raise an error if null=True

Reported by: shaunc <shaun@…> Owned by: Sam Bull
Component: Core (Serialization) Version: dev
Severity: Keywords:
Cc: shaun@…, David Larlet Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (2)

booleanfield-to-python-can-be-none.patch (533 bytes ) - added by shaunc <shaun@…> 17 years ago.
(patch to fix django.db.models.fields.init.py
boolean_no_null_validation.patch (3.2 KB ) - added by Sam Bull 16 years ago.
patch to raise a validation error for BooleanField(null=True)

Download all attachments as: .zip

Change History (14)

by shaunc <shaun@…>, 17 years ago

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

comment:1 by shaunc <shaun@…>, 17 years ago

Cc: shaun@… added

comment:2 by anonymous, 17 years ago

Isn't this what NullBooleanField is for?

comment:3 by shaunc <shaun@…>, 17 years ago

Has patch: unset
Summary: BooleanField can be None if null=TrueBooleanField 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")

comment:4 by James Bennett, 17 years ago

Triage Stage: UnreviewedDesign 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.

comment:5 by Brian Rosner, 17 years ago

Marked #6229 as a duplicate.

comment:6 by David Larlet, 16 years ago

Cc: David Larlet added
Has patch: set

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

== True from the patch is probably useless?

comment:7 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: Design decision neededAccepted

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

comment:8 by Sam Bull, 16 years ago

Owner: changed from nobody to Sam Bull
Status: newassigned

by Sam Bull, 16 years ago

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

comment:9 by Sam Bull, 16 years ago

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.

comment:10 by Jacob, 16 years ago

Triage Stage: AcceptedDesign decision needed

comment:11 by Jacob, 16 years ago

Resolution: fixed
Status: assignedclosed

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

comment:12 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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