My custom adapter isn't used by django-allauth

924 views
Skip to first unread message

Bernard Chhun

unread,
Nov 17, 2014, 9:14:13 AM11/17/14
to django-...@googlegroups.com

Hi everyone,

I'm using django 1.6.5 and django-allauth 0.18.0 and the social login works as expected once we create the social app in the django's admin panel.

So, my next step was trying to change the module's behavior by using adapters.

It looked simple in the docs but somehow, I can't seem to make django-allauth use my custom adapters.

So here's my attempt of trying to pdb into my adapter's methods.

here's my folders/files structure:

.
├── manage.py
├── requirements.freeze
├── foo
   ├── __init__.py
   ├── settings.py
   ├── urls.py
   └── wsgi.py
└── foo_app
    ├── adapters.py
    ├── views.py
    ├── etc...

here's my foo/settings.py file:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sites',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'south',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'foo_app'
)
ACCOUNT_ADAPTER="foo_app.adapters.MyAppAccountAdapter"
SOCIALACCOUNT_ADAPTER="foo_app.adapters.MyAppSocialAccountAdapter"

And here's my foo_app/adapters.py file:

# -*- coding: utf-8 -*-

import pdb

from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter


class FooAppAccountAdapter(DefaultAccountAdapter):
    def save_user(self, request, user, form, commit=true):
        print "FooAppAccountAdapter.save_user"
        pdb.set_trace()
        return super(FooAppAccountAdapter, self).save_user(
            request, user, form, commit
        )


class FooAppSocialAccountAdapter(DefaultSocialAccountAdapter):
    def pre_social_login(self, request, sociallogin):
        print "FooAppSocialAccountAdapter.pre_social_login"
        pdb.set_trace()
        return super(FooAppSocialAccountAdapter, self).pre_social_login(
            request, sociallogin
        )

    def save_user(self, request, sociallogin, form=None):
        print "FooAppSocialAccountAdapter.save_user"
        pdb.set_trace()
        return super(FooAppSocialAccountAdapter, self).save_user(
            request, sociallogin, form
        )

None of my set_trace are working and I think I might just have forgot something in the settings but can't figure it out.

So what I am missing or doing wrong guys/gals ?

Bernard

Sam Solomon

unread,
Nov 17, 2014, 12:30:05 PM11/17/14
to Bernard Chhun, django-...@googlegroups.com
I assume you just an error with renaming to make it safe to post publicly, but are you sure you are calling the right Adapter classes from the settings file (in the example you use MyAppAccountAdapter when trying to call FooAppAccountAdapter)?

If that isn't the issue, for situations like this, what I would do is to find allauth's use of the relevant setting and make sure 1. that the value you expect is getting to allauth (as in that the settings are in the correct file and not later overwritten by something) and 2. that allauth isn't gracefully suppressing an invalid setting (for instance I'd sorta doubt it would be the case, but it's possible that it may not loudly complain if it can't find an adapter at the path given).

Anyways, even if it isn't one of those problems (and there is a good chance it isn't) often tracing (with print debugging or pdb) through 3rd party libraries will help you find the bug (in your own code or less likely, in the 3rd party code) but it also gives you more familiarity with the 3rd party app itself for when you need to do more complicated things or if you want to help improve the open source project in the future.

--
You received this message because you are subscribed to the Google Groups "django-allauth" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-allaut...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bernard Chhun

unread,
Nov 17, 2014, 12:52:01 PM11/17/14
to django-...@googlegroups.com, bernar...@gmail.com
Hi Sam,

Thanks for your answer. 

Indeed, I did switch my classes' name for confidentiality reasons :)

My next step was diving into the module itself, so I'll fork the project on github have a go at it.

Thanks.

Sam Solomon

unread,
Nov 17, 2014, 1:00:29 PM11/17/14
to Bernard Chhun, django-...@googlegroups.com
You probably don't need to fork the project (unless you find a bug and want to submit a fix), you should be able to just edit the files directly on your dev machine (for instance `~/.virtualenvs/<virtualenv_name>/lib/python2.7/site-packages/allauth/account/app_settings.py`)
Reply all
Reply to author
Forward
0 new messages