﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29634	QueryDict fails to urlencode integer values	Vitor Freitas	nobody	"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'
}}}"	Bug	closed	HTTP handling	2.1	Normal	duplicate			Unreviewed	0	0	0	0	1	0
