Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31338 closed Bug (duplicate)

ChangeList parses querystring incorrectly

Reported by: Dan Goldstein Owned by: nobody
Component: contrib.admin Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The ChangeList class in django.contrib.admin does not correctly handle querystrings generated by <select multiple> elements. These elements create querystrings like ?filter=val1&filter=val2. The ChangeList constructor loses all but the last value when it assigns dict(request.GET.items()) to params on this line: https://github.com/django/django/blob/3.0.3/django/contrib/admin/views/main.py#L87

Here’s a code snippet illustrating the problem:

from django.http import QueryDict
qd = QueryDict("key=val1&key=val2&key=val3")
assert qd.getlist("key") == ["val1", "val2", "val3"]  # correct
d = dict(qd.items())
assert d["filter"] == "val3"  # loses val1 and val2

This has been reported before https://code.djangoproject.com/ticket/29121 but the author didn't address the problems with changing the type of ChangeList.params and was marked invalid without comment.

Change History (4)

comment:1 by Carlton Gibson, 4 years ago

Resolution: needsinfo
Status: newclosed

Hi Dan.

I'm happy to accept there's some ticket here, but can you help me to narrow it down?

What filter are you using? (This is for list_filter right?)
None of the built-in filters use a multi-select widget, so can you show your class?
Maybe a sample project to reproduce your issue?

There's an existing ticket #1873 to add multi-select (specifically to the related field list filter, but I think it would generalize).
It may be that this is a duplicate of that?

Thanks.

comment:2 by Dan Goldstein, 4 years ago

Yes, this is for list_filter. This isn't a duplicate of that ticket, but a solution for that ticket would provide an official multi-select solution that we could use instead of our class.

The key to our custom filter class is that the template has a <form> with a <select multiple>. When that form is submitted, it produces a querystring with a repeated key. This page gives a demo: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple

Let me know if there's anything else I can provide to clarify the issue.

comment:3 by Carlton Gibson, 4 years ago

Resolution: needsinfoduplicate

HI Dan, thanks for the follow-up.

OK, I see. I understand how multiple selects work, but I think that functionality has just never been supported, so it's a New Feature and then it looks exactly the same as #1873.
I'll adjust to Duplicate on that basis. (This is for our book-keeping more than anything.)

#1873 is up for grabs: if you'd like to take it on, that would be amazing!

comment:4 by Carlton Gibson, 4 years ago

I've added a comment to #1873 emphasizing your use-case: https://code.djangoproject.com/ticket/1873#comment:28
Thanks!

Note: See TracTickets for help on using tickets.
Back to Top