Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24097 closed Bug (fixed)

Python3 AttributeError with redirect_to_login and lazy LOGIN_URL

Reported by: Peter Schmidt Owned by: nobody
Component: contrib.auth Version: 1.7
Severity: Release blocker 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 (last modified by Peter Schmidt)

See discussion on #18776 to decide whether to keep patching symptoms or fix the root cause.

Ran into the same AttributeError: '__proxy__' object has no attribute 'decode'.

Please see attached test_redirect_to_login.diff or https://github.com/mathspace/django/compare/error-lazylogin-master which passes under Python 2.7 but throws the AttributeError under Python 3.4

One workaround is to explicitly pass the string form of the variable, i.e.

redirect_to_login(next=..., login_url=str(settings.LOGIN_URL))

Attachments (2)

test_redirect_to_login.diff (1.4 KB ) - added by Peter Schmidt 10 years ago.
24097_lazy.diff (3.6 KB ) - added by Peter Schmidt 10 years ago.

Download all attachments as: .zip

Change History (12)

by Peter Schmidt, 10 years ago

Attachment: test_redirect_to_login.diff added

comment:1 by Peter Schmidt, 10 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Could you elaborate about your fix the root cause idea?

by Peter Schmidt, 10 years ago

Attachment: 24097_lazy.diff added

comment:3 by Peter Schmidt, 10 years ago

Re: 24097_lazy.diff​ please see commit comments on https://github.com/mathspace/django/compare/error-lazylogin-master

comment:4 by Peter Schmidt, 10 years ago

Has patch: set

comment:5 by Tim Graham, 10 years ago

Version: master1.7

This doesn't appear to be a regression in master as 1.7 and 1.6 are also affected (seems like a crashing issue worth backporting though).

comment:6 by Claude Paroz, 10 years ago

I would be tempted to solve the issue in django.shortcuts.resolve_url by expanding the URL to a string when it's a lazy instance. Thoughts?

comment:7 by Claude Paroz, 10 years ago

in reply to:  7 comment:8 by Peter Schmidt, 10 years ago

Replying to claudep:

Alternate PR: https://github.com/django/django/pull/3874

+1 here. This also cleans up the quick fix for #18776 which is good.

My attempt at a patch did feel like I was fighting the Zen of Python by getting too involved with str vs bytes.

Thanks to Oktay Sancak for writing the original failing test (albeit under Python2) and Alvin Savoy for supporting contributing back to the community.

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

Resolution: fixed
Status: newclosed

In d7bc37d611b43d58be4b430faf0b9813bcde29c6:

Fixed #24097 -- Prevented AttributeError in redirect_to_login

Thanks Peter Schmidt for the report and the initial patch.
Thanks to ​Oktay Sancak for writing the original failing test and
Alvin Savoy for supporting contributing back to the community.

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

In 7e65876b7c34d0c43c94ba01543a0050270a34fe:

[1.7.x] Fixed #24097 -- Prevented AttributeError in redirect_to_login

Thanks Peter Schmidt for the report and the initial patch.
Thanks to Oktay Sancak for writing the original failing test and
Alvin Savoy for supporting contributing back to the community.
Backport of d7bc37d61 from master.

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