[Django] #30485: Unexpected behavior for django.utils.http.urlencode

16 views
Skip to first unread message

Django

unread,
May 16, 2019, 9:36:48 AM5/16/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
----------------------------------------+------------------------
Reporter: jlubcke | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
The function django.utils.http.urlencode has been changed to give
unexpected result for tuple values (and other iterable objects) in the
case when no iterations is expected:
{{{
>>> django.utils.http.urlencode(dict(a=('a','b')), doseq=False)
'a=%5B%27a%27%2C+%27b%27%5D'
}}}

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.

Django

unread,
May 17, 2019, 9:35:03 AM5/17/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
------------------------------+--------------------------------------
Reporter: Johan Lübcke | Owner: nobody

Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Johan Lübcke):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:1>

Django

unread,
May 17, 2019, 11:21:32 AM5/17/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
------------------------------+--------------------------------------
Reporter: Johan Lübcke | Owner: nobody

Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
May 22, 2019, 5:08:13 AM5/22/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
------------------------------+------------------------------------
Reporter: Johan Lübcke | Owner: nobody

Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
May 22, 2019, 5:54:25 AM5/22/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
-------------------------------------+-------------------------------------
Reporter: Johan Lübcke | Owner: nobody

Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30485#comment:4>

Django

unread,
May 24, 2019, 11:16:34 AM5/24/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
-------------------------------------+-------------------------------------
Reporter: Johan Lübcke | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* 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>

Django

unread,
May 27, 2019, 4:00:52 PM5/27/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
-------------------------------------+-------------------------------------
Reporter: Johan Lübcke | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 19, 2019, 7:04:32 AM6/19/19
to django-...@googlegroups.com
#30485: Unexpected behavior for django.utils.http.urlencode
-------------------------------------+-------------------------------------
Reporter: Johan Lübcke | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages