Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29634 closed Bug (duplicate)

QueryDict fails to urlencode integer values

Reported by: Vitor Freitas Owned by: nobody
Component: HTTP handling Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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:

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:

from django.http.request import QueryDict

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

>> 'user_id=1'

Change History (1)

comment:1 by Vitor Freitas, 6 years ago

Resolution: duplicate
Status: newclosed
Version 0, edited 6 years ago by Vitor Freitas (next)
Note: See TracTickets for help on using tickets.
Back to Top