Opened 12 years ago
Last modified 5 years ago
#22079 new Bug
TestClient serialization of GET params with empty list as value
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | gregchapple1@…, Florian Apolloner, Ahmad Abdallah, Tom Forbes | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Problem:
When POST-ing a parameter whose value is the empty list, TestClient will strip that param-value pair out of the request entirely. In contrast to GET, which passes these along.
Expected behaviour:
They should work the same in the face of an empty list value.
See: https://github.com/django/django/pull/2268 for a patch making POST behave as GET.
Change History (8)
comment:1 by , 12 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 11 years ago
| Patch needs improvement: | set |
|---|
comment:3 by , 11 years ago
| Cc: | added |
|---|
What is the desired behaviour here?
From what I can see, the difference lies with using django.utils.http.urlencode to process the get params.
>>> from django.utils.http import urlencode
>>> data = {'test': ['value1', 'value2']
>>> urlencode(data, doseq=True)
'test=value1&test=value2'
>>> data = {'test': []}
>>> urlencode(data, doseq=True)
''
comment:4 by , 11 years ago
| Cc: | added |
|---|
From my gut I'd say that empty lists should get stripped out entirely, cause there is no way to represent an empty list, "?test=" would be interpreted as a list with one empty item in .getlist which makes no sense.
comment:5 by , 11 years ago
| Summary: | TestClient serialization of POST params with empty list as value → TestClient serialization of GET params with empty list as value |
|---|
comment:6 by , 5 years ago
| Has patch: | unset |
|---|---|
| Patch needs improvement: | unset |
What's the desired behavior here? If it's correcting getlist's handling of empty lists, isn't that more in line with altering QueryDict than changing serialization of GET params?
If we're still changing serialization, we might have to rewrite it ourselves since our current serialization is derived from urllib which is what causes the current bug mentioned by the ticket.
comment:7 by , 5 years ago
| Cc: | added |
|---|
comment:8 by , 5 years ago
| Cc: | added |
|---|
As noted on the pull request, we may want to fix GET rather than POST.
In any case, they should behave similarly.