[Django] #28502: Select widget doesn't accept non-string as value

12 views
Skip to first unread message

Django

unread,
Aug 15, 2017, 10:15:03 PM8/15/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn | Owner: nobody
Hồng Quân |
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords: widget filter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I made a model, with `age_bracket` field, which accepts values from
choices like this:

{{{#!python
AGE_BRACKET = (
# The value in the first column will be saved in Postgres Range field,
# so the upper boundary is not counted, i.e for (18, 25) range, the
value 25
# is not counted.
((None, 18), _('Under 18')),
((18, 25), _('18 - 24')),
((25, 36), _('25 - 35')),
((36, 46), _('36 - 45')),
((46, 56), _('46 - 55')),
((46, 66), _('56 - 65')),
((66, None), _('Above 65')),
)
}}}

However, when being rendered as form, all values become empty string. This
happens since Django 1.11. In Django 1.10, it was OK.
I found the cause is the widget template ''select_option.html''

{{{#!django
<option value="{{ widget.value|stringformat:'s' }}"{% include
"django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
}}}

The `stringformat` filter turns every non-string value to empty string.
My suggestion is that, update `stringformat` so that it returns
`str(value)` if value is not a string. Is it right way to do?

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

Django

unread,
Aug 16, 2017, 2:35:23 AM8/16/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
----------------------------------+------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Claude Paroz):

* version: 1.11 => master
* component: Forms => Template system
* stage: Unreviewed => Accepted


Comment:

I also think that `stringformat` should be improved to accept tuples as
its base `value`. In Python the printf syntax special cases tuples as it
considers them as a list of placeholder values. This does not make sense
in `stringformat` as the string containing the placeholder is always a
single placeholder.

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

Django

unread,
Aug 16, 2017, 7:30:31 AM8/16/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Srinivas Reddy Thatiparthy):

* owner: nobody => Srinivas Reddy Thatiparthy
* status: new => assigned


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

Django

unread,
Aug 16, 2017, 8:29:18 AM8/16/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Srinivas Reddy Thatiparthy):

PR - https://github.com/django/django/pull/8914

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

Django

unread,
Aug 16, 2017, 9:25:13 AM8/16/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:4>

Django

unread,
Aug 16, 2017, 1:59:18 PM8/16/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Srinivas Reddy Thatiparthy):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:5>

Django

unread,
Aug 19, 2017, 3:26:34 PM8/19/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"a64f88f5be0f680a7261b500fd9243501e6a7745" a64f88f]:
{{{
#!CommitTicketReference repository=""
revision="a64f88f5be0f680a7261b500fd9243501e6a7745"
Refs #28502 -- Completed stringformat filter tests
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:6>

Django

unread,
Aug 20, 2017, 7:02:47 AM8/20/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: widget filter | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:7>

Django

unread,
Aug 21, 2017, 3:05:45 AM8/21/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: widget filter | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

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


Comment:

In [changeset:"4ead705cb3cf04bb7551ac037d1e11f682b62bcf" 4ead705c]:
{{{
#!CommitTicketReference repository=""
revision="4ead705cb3cf04bb7551ac037d1e11f682b62bcf"
Fixed #28502 -- Made stringformat template filter accept tuples
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:8>

Django

unread,
Aug 22, 2017, 8:45:25 AM8/22/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: widget filter | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"ed77bea58274e11e5a9e4c8b9650f50deb8a2b26" ed77bea]:
{{{
#!CommitTicketReference repository=""
revision="ed77bea58274e11e5a9e4c8b9650f50deb8a2b26"
Refs #28502 -- Complemented stringformat tuple handling/test.

An additional test and a code change were suggested in a late review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:9>

Django

unread,
Aug 22, 2017, 9:00:49 AM8/22/17
to django-...@googlegroups.com
#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: widget filter | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"dd82f1df556561233eab6a4a2032c2bb306dec87" dd82f1df]:
{{{
#!CommitTicketReference repository=""
revision="dd82f1df556561233eab6a4a2032c2bb306dec87"
[1.11.x] Fixed #28502 -- Made stringformat template filter accept tuples.

Backport of 4ead705cb3cf04bb7551ac037d1e11f682b62bcf and
ed77bea58274e11e5a9e4c8b9650f50deb8a2b26 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:10>

Reply all
Reply to author
Forward
0 new messages