[Django] #35523: query_string cannot use variables as keys

15 views
Skip to first unread message

Django

unread,
Jun 13, 2024, 3:50:13 AM6/13/24
to django-...@googlegroups.com
#35523: query_string cannot use variables as keys
-------------------------------------------+------------------------
Reporter: Sarah Boyce | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 5.1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Raised by Florian here: https://forum.djangoproject.com/t/adding-a
-template-tag-to-generate-query-strings/24521/15

If we are to add a test:
{{{#!diff
--- a/tests/template_tests/syntax_tests/test_query_string.py
+++ b/tests/template_tests/syntax_tests/test_query_string.py
@@ -98,3 +98,16 @@ class QueryStringTagTests(SimpleTestCase):
msg = "'Context' object has no attribute 'request'"
with self.assertRaisesMessage(AttributeError, msg):
self.engine.render_to_string("query_string_no_request_no_query_dict")
+
+ @setup(
+ {
+ "query_string_var_key": '{% with key="var_key" %}{%
query_string key=2 %}'
+ "{% endwith %}"
+ }
+ )
+ def test_query_string_with_variable_key(self):
+ request = self.request_factory.get("/")
+ template = self.engine.get_template("query_string_var_key")
+ context = RequestContext(request)
+ output = template.render(context)
+ self.assertEqual(output, "?var_key=2")
}}}

This fails with `AssertionError: '?key=2' != '?var_key=2'`.

One suggestion is to quote literal keys eg. `{% query_string var_key=1
'other_key'=2 %}`

Refs #10941, design decision required, potential release blocker
--
Ticket URL: <https://code.djangoproject.com/ticket/35523>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2024, 5:04:29 AM6/13/24
to django-...@googlegroups.com
#35523: query_string cannot use variables as keys
---------------------------------+--------------------------------------
Reporter: Sarah Boyce | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 5.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Carsten Fuchs):

This is why my original code supported dictionaries for input.
See the last example at
https://code.djangoproject.com/ticket/10941#comment:33, repeated here for
reference:
{{{
{# Overwrite month and year with precomputed values, e.g. with
next_month_year = {'month': 1, 'year': 2022}, and clear the day: #}
{% query_string request.GET next_month_year day=None %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35523#comment:1>

Django

unread,
Jun 18, 2024, 3:17:22 AM6/18/24
to django-...@googlegroups.com
#35523: query_string cannot use variables as keys
---------------------------------+--------------------------------------
Reporter: Sarah Boyce | Owner: nobody
Type: Bug | Status: closed
Component: Template system | Version: 5.1
Severity: Release blocker | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Sarah Boyce):

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

Comment:

Based off the conclusion in the discussion
--
Ticket URL: <https://code.djangoproject.com/ticket/35523#comment:2>
Reply all
Reply to author
Forward
0 new messages