#31369: Deprecate NullBooleanField -------------------------------------+------------------------------------- Reporter: David Smith | Owner: Hristiyan Type: | Ivanov Cleanup/optimization | Status: assigned Component: Database layer | Version: 3.0 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by David Smith): Hi hristiy4n, Thanks for picking this up. I had a brief look at the code before raising the issue but thought the principle was important to agree before lots of detailed work. I agree a deprecation message is key to this. I also think a bit more thought at this stage would be beneficial in the long run. I'd suggest that 'just' issuing a deprecation warning at this stage we may uncover something later which is tricky to resolve. Here are my more detailed notes having spent some time looking at it in more detail. There are three elements which we should consider deprecating. Is it just the first one at this stage, the top two (I think this is the intent), or a bit more of a wider tidy up and go for all three? - There is [https://docs.djangoproject.com/en/3.0/ref/models/fields/#nullbooleanfield nullboolean model field] - and [https://docs.djangoproject.com/en/3.0/ref/forms/fields/#nullbooleanfield nullbooleanfield field] - and the associated [https://docs.djangoproject.com/en/3.0/ref/forms/widgets/#nullbooleanselect widget]. Note this widget is currently used when `null=True` My main concern about just adding a deprecation notice is that the two `BooleanField`s work slightly differently. The `models.fields.BooleanField` acts more like the `forms.fields.NullBooleanField` than `forms.fields.BooleanField`. Whilst I think the preference should be to deprecate both `NullBooleanField`s do we need to change the behaviour of `forms.fields.BooleanField` to mirror `models.fields.BooleanField` when `null=True`. I hope my code sample below, explains it more clearly that what I've written out above! {{{ >>> from django.forms.fields import NullBooleanField >>> f = NullBooleanField() >>> f.clean("True") True >>> f.clean("") # returns null >>> f.clean(False) False >>> from django.forms.fields import BooleanField >>> f = BooleanField() >>> f.required = False >>> f.clean(True) True >>> f.clean("") False >>> f.clean(False) False >>> from django.db.models import fields >>> f = fields.BooleanField(null=True) >>> f.blank = True >>> f.clean(True, "test") True >>> f.clean("", "test") # returns null >>> f.clean(False, "test") False }}} -- Ticket URL: <https://code.djangoproject.com/ticket/31369#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.b537ed0ed3008af952ae852537a7d7f5%40djangoproject.com.