Opened 8 years ago

Closed 8 years ago

Last modified 8 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 8 years ago.
24097_lazy.diff (3.6 KB) - added by Peter Schmidt 8 years ago.

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by Peter Schmidt

Attachment: test_redirect_to_login.diff added

comment:1 Changed 8 years ago by Peter Schmidt

Description: modified (diff)

comment:2 Changed 8 years ago by Claude Paroz

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Could you elaborate about your fix the root cause idea?

Changed 8 years ago by Peter Schmidt

Attachment: 24097_lazy.diff added

comment:3 Changed 8 years ago by Peter Schmidt

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

comment:4 Changed 8 years ago by Peter Schmidt

Has patch: set

comment:5 Changed 8 years ago by Tim Graham

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 Changed 8 years ago by Claude Paroz

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 Changed 8 years ago by Claude Paroz

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

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 Changed 8 years ago by Claude Paroz <claude@…>

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 Changed 8 years ago by Claude Paroz <claude@…>

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