#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.82d4d232ed159bb0838d7640dcdea8ec%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to