Skip to content

Commit ed77bea

Browse files
claudeptimgraham
authored andcommitted
Refs #28502 -- Complemented stringformat tuple handling/test.
An additional test and a code change were suggested in a late review.
1 parent 7bba824 commit ed77bea

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

django/template/defaultfilters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ def stringformat(value, arg):
223223
See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
224224
for documentation of Python string formatting.
225225
"""
226+
if isinstance(value, tuple):
227+
value = str(value)
226228
try:
227-
if isinstance(value, tuple):
228-
return ('%' + str(arg)) % str(value)
229229
return ("%" + str(arg)) % value
230230
except (ValueError, TypeError):
231231
return ""

docs/releases/1.11.5.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Bugfixes
1313
in GEOS 3.6.2) (:ticket:`28441`).
1414

1515
* Fixed test database creation with ``cx_Oracle`` 6 (:ticket:`28498`).
16+
17+
* Fixed select widget rendering when option values are tuples (:ticket:`28502`).

tests/template_tests/filter_tests/test_stringformat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ def test_invalid(self):
3939
self.assertEqual(stringformat(1, 'z'), '')
4040
self.assertEqual(stringformat(object(), 'd'), '')
4141
self.assertEqual(stringformat(None, 'd'), '')
42+
self.assertEqual(stringformat((1, 2, 3), 'd'), '')

0 commit comments

Comments
 (0)