[Django] #29247: Fix choices ignoring the defined blank value

2 views
Skip to first unread message

Django

unread,
Mar 22, 2018, 9:29:15 AM3/22/18
to django-...@googlegroups.com
#29247: Fix choices ignoring the defined blank value
--------------------------------------+-------------------------
Reporter: orlnub123 | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Keywords: choices
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+-------------------------
While sifting through the source code to understand the internals for a
package I'm making, I stumbled upon what looked like a bug.

These lines right here:
{{{
named_groups = isinstance(choices[0][1], (list, tuple))
blank_defined = not named_groups and any(choice in ('', None) for choice,
__ in choices)
}}}
And indeed a bug it was.

The problem was that, had you defined your choices first with a group and
then later on a choice that defined the blank value, the current
implementation would skip right over it! So you would end up with having
both the default blank value and the one you've defined, which doesn't
look very pretty.

I've created a pull request on github that fixes the issue
[https://github.com/django/django/pull/9813 here.]

--
Ticket URL: <https://code.djangoproject.com/ticket/29247>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 22, 2018, 9:31:30 AM3/22/18
to django-...@googlegroups.com
#29247: Choices ignoring the defined blank value
---------------------------+--------------------------------------

Reporter: orlnub123 | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:

Keywords: choices | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:1>

Django

unread,
Mar 24, 2018, 8:18:08 PM3/24/18
to django-...@googlegroups.com
#29247: A custom blank value in model field choices doesn't work when using named
groups
-------------------------------------+-------------------------------------

Reporter: orlnub123 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
* component: Forms => Database layer (models, ORM)


--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:2>

Django

unread,
Apr 20, 2018, 11:25:06 AM4/20/18
to django-...@googlegroups.com
#29247: A custom blank value in model field choices doesn't work when using named
groups
-------------------------------------+-------------------------------------
Reporter: orlnub123 | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: choices | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"21420096c4db78ccb8f549a29d662cff870d363c" 2142009]:
{{{
#!CommitTicketReference repository=""
revision="21420096c4db78ccb8f549a29d662cff870d363c"
Fixed #29247 -- Allowed blank model field choice to be defined in nested
choices.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:3>

Reply all
Reply to author
Forward
0 new messages