Opened 9 years ago

Closed 9 years ago

#25424 closed Bug (fixed)

"AttributeError: '__proxy__' object has no attribute 'decode'" using reverse_lazy in test client

Reported by: Travis Jensen Owned by: Travis Jensen
Component: Testing framework Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is basically the same as this bug, just starting from the test client. The relevant stack trace:

Traceback (most recent call last):
  File "$SRC/tests/test_planner.py", line 49,
    r = self.client.get(reverse_lazy('generator'))
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/client.py", line 500, in get
    **extra)
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/client.py", line 303, in get
    return self.generic('GET', path, secure=secure, **r)
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/client.py", line 357, in generic
    parsed = urlparse(path)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/parse.py", line 292, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/parse.py", line 112, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/parse.py", line 96, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: '__proxy__' object has no attribute 'decode'

Change History (5)

comment:1 by Travis Jensen, 9 years ago

Owner: changed from nobody to Travis Jensen
Status: newassigned

comment:2 by Travis Jensen, 9 years ago

I've created a reproducer and a fix for this, based on the fix for 18776. It is available at https://github.com/SoftwareMaven/django/tree/ticket_25424.

This is my first foray into contributing to Django, so if there is anything I missed in terms of process and what-not, please let me know.

comment:3 by Claude Paroz, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

Could you please transform your branch into a pull request ?

comment:5 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 1a09b3c:

Fixed #25424 -- Use force_str for test client URLs.

urlparse() fails with an AttributeError ("'proxy' object has no
attribute 'decode'") if reverse_lazy is used to look up the URL
(this is exactly the same problem that caused ticket #18776). The
solution is to use force_str() on the path before handing it to
urlparse().

Note: See TracTickets for help on using tickets.
Back to Top