python-social-auth icon indicating copy to clipboard operation
python-social-auth copied to clipboard

Error while saving extra_data for new users

Open dragomireckijj opened this issue 11 years ago • 4 comments

I've got AttributeError at /complete/facebook/ just before redirecting newly registered user to LOGIN_REDIRECT_URL: Exception Value: 'str' object has no attribute 'update'

  • Request Method: GET
  • Request URL: http://appdomain/complete/facebook/?redirect_state=~&code=~&state=~
  • Django Version: 1.9
  • Python Version: 2.7.6
  • Installed Applications:
    • 'django.contrib.admin',
    • 'django.contrib.auth',
    • 'django.contrib.contenttypes',
    • 'django.contrib.sessions',
    • 'django.contrib.messages',
    • 'django.contrib.staticfiles',
    • 'django.contrib.gis',
    • 'social.apps.django_app.default',
    • 'myapp'
  • Installed Middleware:
    • 'django.contrib.sessions.middleware.SessionMiddleware',
    • 'django.middleware.common.CommonMiddleware',
    • 'django.middleware.csrf.CsrfViewMiddleware',
    • 'django.contrib.auth.middleware.AuthenticationMiddleware',
    • 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    • 'django.contrib.messages.middleware.MessageMiddleware',
    • 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    • 'django.middleware.security.SecurityMiddleware']

Traceback:

File ".../social/pipeline/social_auth.py" in load_extra_data 92. social.set_extra_data(extra_data)

File ".../social/storage/django_orm.py" in set_extra_data 16. if super(DjangoUserMixin, self).set_extra_data(extra_data)

File ".../social/storage/base.py" in set_extra_data 85. self.extra_data.update(extra_data)

User and related social auth was created correctly, except extra_data field of UserSocialAuth model (it was empty JSON string). Every next attempt was completed without any errors, updating extra_data field with facebook related data in JSON format.

Error appears again if User and related UserSocialAuth models are removed. Seems like set_extra_data function assumes self.extra_data to be dict, but str given for new users.

My app is default django project appended using PSA documentation guides.

dragomireckijj avatar Oct 22 '15 18:10 dragomireckijj

Here is what was happened:

  1. db engine is PostgreSQL in my project
  2. migration for JSONField extra_data sets {} as default value for new rows
  3. social.pipeline.social_auth.load_extra_data calls set_extra_data method of UserMixin
  4. set_extra_data reads extra_data attribute of newly created model (which contains {} string at this time) and tries to use dict.update method on it.

After appending and not isinstance(self.extra_data, str) to condition on line 84 of social/storage/base.py I was able to fix this issue.

dragomireckijj avatar Oct 26 '15 19:10 dragomireckijj

I am facing the same problem. I don't think it reached the master branch, did it?

evcb avatar Feb 23 '16 17:02 evcb

I made the update and sent a proposal for the fix. Let's see if someone can approve it.

evcb avatar Feb 23 '16 17:02 evcb

The fix was merged.

omab avatar Dec 26 '16 20:12 omab