Opened 16 years ago
Closed 10 years ago
#10928 closed Bug (fixed)
BooleanField: different behaviour when default=callable
Reported by: | 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)
Change History (11)
comment:1 by , 16 years ago
comment:2 by , 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 , 16 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
comment:4 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 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 , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:9 by , 10 years ago
comment:10 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Oh, hit submit too fast. Basically, the callable-form emits, when used in a ModelForm (for example the admin), the following hidden initial-field:
This has the effect that
form.has_changed()
is always True, so that extra forms of formsets are always considered for validation.