0

My social-auth pipeline is as follows:

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.social_auth.associate_by_email',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'useraccounts.models.create_user_profile'
)

When 'useraccounts.models.create_user_profile' does following:

request = kwargs.get('request')
do_something(session_key=request.session.session_key)

Following error comes:

'QueryDict' object has no attribute 'session'

'Request' dictionary has elements with following keys: state, code, prompt, session_state, authuser

I am using Django version 1.5.5. The problem is coming since I have upgraded python-social-auth from v0.1.17 to v0.2.4

Sid
  • 589
  • 6
  • 20
  • `request = kwargs.get('request')` is not `QuerySet`, its `QueryDict`. You can use like this: `request['session']['session_key']`. – Usman Maqbool Aug 16 '16 at 13:27
  • Request don't have any key named session hence there is no benefit in changing access method. Though I tried and got error: MultiValueDictKeyError: "Key 'session' not found in – Sid Aug 17 '16 at 05:48
  • print result of request. – Usman Maqbool Aug 17 '16 at 06:29
  • request: – Sid Aug 17 '16 at 07:34
  • I commented out the above line accessing request.session and the code broke later saying request.user is not present. Both request and user are set by middleware but I checked again and they are mentioned in settings. This might help in isolating the issue – Sid Aug 17 '16 at 07:38
  • http://stackoverflow.com/questions/5130639/django-setting-a-session-and-getting-session-key-in-same-view this link may help you. – Usman Maqbool Aug 17 '16 at 07:40
  • This could be useful but the problem start occurring after updating python-social-auth. Hence it is better to find the issue rather than introducing each missing parameter through middleware or other ways – Sid Aug 17 '16 at 08:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121134/discussion-between-usman-maqbool-and-sid). – Usman Maqbool Aug 17 '16 at 08:43

2 Answers2

1

https://github.com/omab/python-social-auth/issues/978

Try to use

strategy.request

to access django request.

  • This looks interesting, it should have been mentioned in docs. Also, my code was able to get 'session' and 'user' from kwargs request before upgrade, then why this is happening after upgrade, any idea? – Sid Aug 22 '16 at 09:36
  • Sorry, can't answer on your question, it's first time how i'm using this module :) My auth work properly, how about you? – Максим Стукало Aug 22 '16 at 09:56
  • I implemented the suggestion and everything is working fine now. Thanks a lot ! – Sid Aug 22 '16 at 17:38
0

This may be because user_details function doesn't pass anything to next function in pipeline. As per your requirement you might need to change the order of functions in your pipeline:

Check this: https://github.com/omab/python-social-auth/blob/master/social/pipeline/user.py#L75

Nitin Verma
  • 206
  • 2
  • 14