Opened 17 months ago

Last modified 6 months ago

#22079 new Bug

TestClient serialization of GET params with empty list as value

Reported by: code.djangoproject.com@… Owned by: nobody
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: gregchapple1@…, apollo13 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
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 (5)

comment:1 Changed 16 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

As noted on the pull request, we may want to fix GET rather than POST.

In any case, they should behave similarly.

comment:2 Changed 13 months ago by timo

  • Patch needs improvement set

comment:3 Changed 13 months ago by gchp

  • Cc gregchapple1@… 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 Changed 9 months ago by apollo13

  • Cc apollo13 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 Changed 6 months ago by collinanderson

  • Summary changed from TestClient serialization of POST params with empty list as value to TestClient serialization of GET params with empty list as value
Note: See TracTickets for help on using tickets.
Back to Top