Opened 9 years ago

Closed 6 years ago

#26168 closed Cleanup/optimization (fixed)

BooleanField is forced to be blank=True

Reported by: fengyehong Owned by: Lynn Cyrin
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: BooleanField
Cc: jonas@…, Kamil Gałuszka Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://github.com/django/django/tree/master/django/db/models/fields#L1017

    def __init__(self, *args, **kwargs):
        kwargs['blank'] = True
        super(BooleanField, self).__init__(*args, **kwargs)

blank is set to True forcibly

I want my BooleanField always explicitly set(without a default value), like this:

myflag = models.BooleanField(blank=False)

but with this kwargs['blank'] =True, Django does not complain if field myflag not set, but try to use default of BooleanField(in 1.7.5, None) which lead to exception when saving~

I think force blank = True makes sense for NullBooleanField, but for BooleanField, we can leave it to user.

Thanks.

Change History (6)

comment:1 by Tim Graham, 9 years ago

Summary: Django forcibly allow BooleanField blankBooleanField is forced to be blank=True
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

See #22282 and #23130 for some related discussion. I'm not sure what the proper resolution is, but I'll accept the ticket since this this has come up several time. We can at least document the reasons for this if it can't be changed for backwards compatibility reasons.

comment:2 by Jonas Haag, 9 years ago

There's an outdated patch in #23130, which I still think is the best solution to this problem. Somehow, I've never gotten around to finishing the patch, but I think it should take no more than an hour of time to get it up to date and pass the test suite.

comment:3 by Jonas Haag, 9 years ago

Cc: jonas@… added

comment:4 by Lynn Cyrin, 7 years ago

Owner: changed from nobody to Lynn Cyrin
Status: newassigned

The WIP PR I made for #23130 addresses this.

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:5 by Kamil Gałuszka, 6 years ago

Cc: Kamil Gałuszka added

I think this was fixed with https://github.com/django/django/pull/8467 and #29227 . This ticket can be close then?

comment:6 by Tim Graham, 6 years ago

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