One would expect the same as the standard library version (Note the first
and last characters has been replaced by square brackets):
{{{
>>> urllib.parse.urlencode(dict(a=('a', 'b')), doseq=False)
'a=%28%27a%27%2C+%27b%27%29'
}}}
If the value is a list, the result if what one would expect:
{{{
>>> django.utils.http.urlencode(dict(a=['a','b']), doseq=False)
'a=%5B%27a%27%2C+%27b%27%5D'
>>> urllib.parse.urlencode(dict(a=['a', 'b']), doseq=False)
'a=%5B%27a%27%2C+%27b%27%5D'
}}}
Note: This is a problem when one has objects that has a `__str__` method
defined, returning the value one would want to be in the urlencode result,
but the object by coincidence is also iterable.
--
Ticket URL: <https://code.djangoproject.com/ticket/30485>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:1>
* cc: François Freitag (added)
Comment:
Asking François to comment. This is related to #28679.
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:2>
* stage: Unreviewed => Accepted
Comment:
OK, having conferred with Mariusz, I'm going to Accept this as a bug on
2.2, to be fixed in master, rather than backported to 2.2. (We'll look at
the final patch before deciding finally there.)
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"0670b1b403087ec2d311321597b387ad541ea2e0" 0670b1b4]:
{{{
#!CommitTicketReference repository=""
revision="0670b1b403087ec2d311321597b387ad541ea2e0"
Fixed #30485 -- Adjusted django.utils.http.urlencode for doseq=False case.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"df46b329e0900e9e4dc1d60816c1dce6dfc1094e" df46b329]:
{{{
#!CommitTicketReference repository=""
revision="df46b329e0900e9e4dc1d60816c1dce6dfc1094e"
Refs #30485 -- Avoided unnecessary instance checks in urlencode.
Given doseq defaults to False it should avoid an unnecessary instance
check in most cases.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:6>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"b903bb438f96f76f17459f51d5f33b203fd15846" b903bb43]:
{{{
#!CommitTicketReference repository=""
revision="b903bb438f96f76f17459f51d5f33b203fd15846"
Refs #30485 -- Removed non-representative test that emitted a warning.
Previously, when running the Django test suite with warnings enabled,
the following was emitted:
/usr/lib64/python3.7/urllib/parse.py:915: BytesWarning: str() on a
bytearray instance
v = quote_via(str(v), safe, encoding, errors)
This occurred due to the bytearray() being passed to
urllib.parse.urlencode() which eventually calls str() on it. The test
does not represent desired real world behavior. Rather than test for and
assert strange unspecified behavior that emits a warning, remove it.
This was also discussed in PR #11374.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:7>