Opened 16 years ago

Closed 9 years ago

#10928 closed Bug (fixed)

BooleanField: different behaviour when default=callable

Reported by: alex@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using a callable, the behaviour of the BooleanField is different from just using a constant. Example:

foo = models.BooleanField(default=lambda: False)

vs.

foo = models.BooleanField(default=False)

Attachments (1)

10928-r11178.diff (2.0 KB ) - added by SafPlusPlus <freark@…> 15 years ago.
Regression test for #10928

Download all attachments as: .zip

Change History (11)

comment:1 by alex@…, 16 years ago

Oh, hit submit too fast. Basically, the callable-form emits, when used in a ModelForm (for example the admin), the following hidden initial-field:

<input type="hidden" name="initial-child1_set-0-foo" value="False" id="id_child1_set-0-foo" />

This has the effect that form.has_changed() is always True, so that extra forms of formsets are always considered for validation.

comment:2 by alex@…, 16 years ago

Ok, I found out that I can work around by returning None instead of False from the callable, the value="" attribute is left out in the hidden initial. A possible fix would be to make the CheckboxInput widget accept u"False" as False in the _has_changed check, or by preventing the hidden initial field from having value="False" in the first place.

comment:3 by Thejaswi Puthraya, 16 years ago

Component: UncategorizedDatabase layer (models, ORM)

comment:4 by Chris Beaven, 15 years ago

Triage Stage: UnreviewedAccepted

by SafPlusPlus <freark@…>, 15 years ago

Attachment: 10928-r11178.diff added

Regression test for #10928

comment:5 by SafPlusPlus <freark@…>, 15 years ago

Added a test, which is hopefully correct. Maybe I should've named the file in way that more reflects that it only contains a test and not a fix, but then again, I'm just a newbie so I may get away with it. :)

comment:6 by Luke Plant, 14 years ago

Severity: Normal
Type: Bug

comment:7 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 by Tim Graham, 9 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top