Django-allauth: social account adapter override save_user

Created on 28 Aug 2017  路  4Comments  路  Source: pennersr/django-allauth

I'm trying to override the save user method in account adapter, but the save_user method never seems to get hit.

adapter.py

class DefaultOverrideAccountAdapter(DefaultAccountAdapter):
    def save_user(self, request, user, form, commit=False):
        user = super(DefaultOverrideAccountAdapter, self).save_user(request, user, form, commit)
        user.gender = form.cleaned_data.get('gender')
        user.date_of_birth = form.cleaned_data.get('date_of_birth')
        if commit:
            user.save()

settings.py
ACCOUNT_ADAPTER = 'adapter.DefaultOverrideAccountAdapter'

Most helpful comment

I know it's too late for this but hopefully will be useful for somebody. Here's my workaround:

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
    def save_user(self, request, sociallogin, form):
        user = super(CustomSocialAccountAdapter, self).save_user(request, sociallogin, form)
        # Do what ever you want with the user
        return user

settings.py
SOCIALACCOUNT_ADAPTER = 'path.to.CustomSocialAccountAdapter'

All 4 comments

I have the same issue. Is there any workarounds?

I know it's too late for this but hopefully will be useful for somebody. Here's my workaround:

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
    def save_user(self, request, sociallogin, form):
        user = super(CustomSocialAccountAdapter, self).save_user(request, sociallogin, form)
        # Do what ever you want with the user
        return user

settings.py
SOCIALACCOUNT_ADAPTER = 'path.to.CustomSocialAccountAdapter'

I don't think there is an issue in allauth here. For example, try putting a pdb into the save_user method and run the test suite. You'll clearly see it being hit.

I am not sure why overriding save_user is returning me a server error (500) in its callback URL. I am not sure why this is happening!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hyunwoona picture hyunwoona  路  4Comments

nordbit picture nordbit  路  5Comments

aliabbas-2012 picture aliabbas-2012  路  6Comments

JohnnyKing94 picture JohnnyKing94  路  4Comments

eve1234 picture eve1234  路  3Comments