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
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
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.

Regards,
Jon
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/36c2fd74-cd8e-4769-b742-a5c17cad8a28%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

David Winterbottom

unread,
Nov 11, 2013, 5:11:12 PM11/11/13
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.

John,








--
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

David Winterbottom

unread,
Nov 12, 2013, 5:45:39 AM11/12/13
to django-oscar
Reply all
Reply to author
Forward
0 new messages