Commit
dict() applied to QueryDict produces a dictionary whose values are string representations of lists, like "[u'44']". This is because QueryDict associates each key with a list of values even if there is only one value. QueryDict's dict() method translates each list of values into a string repr of *one* value from the original list. This means data is thrown away for any keys with multiple values in the QueryDict. This is a problem for certain form controls.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
|
||
@register.function | ||
def page_url(request, page): | ||
params = dict(request.GET) | ||
params = request.GET.dict() | ||
params['page'] = page | ||
return urlparams('', **params) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Osmose
|
1 comment
on commit 3efb06c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(To address your previous question, @bobsilverberg.)
There are two problems in master right now:
- generating URLs with brackets around GET parameter values (which this commit fixes);
- losing some information about GET parameters that are associated with multiple values.
I propose to open a different bug for the second problem as it is significant and unrelated to the profile page.
I would also add the following test to address the issue:
def test_repeats(self):
"""
GET parameters with multiple values should have all their
values preserved
"""
request = Mock(GET=QueryDict('foo=bar&baz=5&foo=ok'))
url = urlparse.urlsplit(page_url(request, 4))
args = urlparse.parse_qs(url.query)
eq_(args, {'foo': ['bar', 'ok'], 'baz': ['5'], 'page': ['4']})
(Copying comments from my broken pull-request to continue discussion here.)
FWIW, see https://github.com/mozilla/funfactory/blob/master/funfactory/helpers.py#L48 and note that "New query params will be appended to exising parameters, except duplicate names, which will be replaced." Since
urlparams('', QueryDict('foo=bar&baz=5&foo=ok'))
yields a URL that ends with"foo=[u'bar',+u'ok']&baz=[u'5']"
, I thinkurlparams
is expecting a dictionary where each key has a single value (not a list of values)."@Osmose can we get your thoughts on this, as you wrote the original code? Is the above change OK/needed, or do we need to keep the code as is and find another way of dealing with the fact that we are having issues with the URL that is generated when doing pagination and filtering at the same time?"