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.
* status: new => closed
* resolution: => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/29634#comment:1>