request.strategy conflicting with python-social-auth request.strategy
214 views
Skip to first unread message
Nitish Rathi
unread,
Nov 8, 2013, 9:58:18 PM11/8/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hi everyone:
I've just migrated my oscar application from django-social-auth to python-social-auth. Now, it turns out that both oscar and python-social-auth want to add and use an attribute named 'strategy' on the request object, thus leading to a problem since they each assume that request.strategy is of a type that they expect.
Any suggestions for a solution or workaround? I think any attributes set on the request by a library or framework like oscar or python-social-auth should be "namespaced", e.g. "oscar_strategy", "social_auth_strategy", etc. Still not foolproof, but at least less likely to lead to conflicts between libraries. Alternatively, make the names of any such attributes configurable.
In any case, appreciate any suggestions or help in resolving the conflict.
Thank you,
Nitish
Jonathan Moss
unread,
Nov 10, 2013, 4:22:18 PM11/10/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hi Nitish,
Good spot and thanks for letting us know.
@David - I can see a couple of options here that I think are worth
highlighting.
Firstly changing the name as suggested by Nitish, especially as
'strategy' is a fairly generic name. The second is a little more
invasive but I think a better overall plan. That is to create an 'oscar'
dictionary or object with the request object to act as a container for
all oscar related additions. This means that there should be no
conflicts like this going forward.
I would suggest that for the 0.6 release that items that where already
in the request (e.g. basket) should remain so (in addition to being in
the 'oscar' container) but perhaps with a deprecated warning with final
removal in 0.7 or later.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-oscar
Nitish,
Thanks for pointing this out - I'm glad you did before we released 0.6.
I think John's suggestion is a good one. We'll create a namespace of sorts on the request object so Oscar can keep things there without fear of conflict. Access to the strategy class will become:
request.oscar.strategy
Namespacing is actually something of a problem in Django (for a library writer at least). There are lots of places were you have to be careful of clashes - like static files, templates, management commands, template tags, and now custom request attributes.