Opened 5 years ago

Closed 3 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: master
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


    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.


Change History (6)

comment:1 Changed 5 years ago by Tim Graham

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 Changed 5 years ago by Jonas Haag

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 Changed 5 years ago by Jonas Haag

Cc: jonas@… added

comment:4 Changed 3 years ago by Lynn Cyrin

Owner: changed from nobody to Lynn Cyrin
Status: newassigned

The WIP PR I made for #23130 addresses this.

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

comment:5 Changed 3 years ago by Kamil Gałuszka

Cc: Kamil Gałuszka added

I think this was fixed with and #29227 . This ticket can be close then?

comment:6 Changed 3 years ago by Tim Graham

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