[Django] #29634: QueryDict fails to urlencode integer values

5 views
Skip to first unread message

Django

unread,
Aug 3, 2018, 6:14:38 PM8/3/18
to django-...@googlegroups.com
#29634: QueryDict fails to urlencode integer values
-----------------------------------------+------------------------
Reporter: Vitor Freitas | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
This bug was introduced in the 2.1 version.

If you have a QueryDict and try to call the `urlencode` method having an
`int` value, it will give you the following exception:

{{{
Traceback (most recent call last):
File "/Users/vitorfs/Development/colossus/venv/lib/python3.6/site-
packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-10-7ef4f2f1bad4>", line 1, in <module>
q2.urlencode()
File "/Users/vitorfs/Development/colossus/venv/lib/python3.6/site-
packages/django/http/request.py", line 524, in urlencode
for v in list_
File "/Users/vitorfs/Development/colossus/venv/lib/python3.6/site-
packages/django/http/request.py", line 524, in <genexpr>
for v in list_
AttributeError: 'int' object has no attribute 'encode'
}}}

How to reproduce:

{{{#!python
from django.http.request import QueryDict

qd = QueryDict(mutable=True)
qd['user_id'] = 1
qd.urlencode()
}}}

Change point where I believe the bug was introduced:
https://github.com/django/django/commit/7d96f0c49ab750799860e42716d7105e11de44de
#diff-0eb6c5000a61126731553169fddb306eR523

A way to remedy the bug for now is to cast the value to string:

{{{#!python
from django.http.request import QueryDict

qd = QueryDict(mutable=True)
qd['user_id'] = str(1)
qd.urlencode()

>> 'user_id=1'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29634>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 3, 2018, 6:28:22 PM8/3/18
to django-...@googlegroups.com
#29634: QueryDict fails to urlencode integer values
-------------------------------+--------------------------------------

Reporter: Vitor Freitas | Owner: nobody
Type: Bug | Status: closed

Component: HTTP handling | Version: 2.1
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Vitor Freitas):

* status: new => closed
* resolution: => duplicate


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

Reply all
Reply to author
Forward
0 new messages