Django 1.6b3 incompatibility? #386

Closed
jaddison opened this Issue Sep 18, 2013 · 2 comments

2 participants

@jaddison

With Django 1.6b3, I am seeing this exception when trying to login via Facebook:

Environment:

Request Method: GET
Request URL: http://localhost:8001/accounts/facebook/login/callback/?code=AQCiIqptDuvPLLaQ7vvaOF0HI2fwqCHIC1XYv27MOADOt7IDEi1bM-Y1N0lh8RUL_70P753jkSf8UTRzdpyfU-PhQKv-vpZh5DJazOEiXs12wO5LKIU-PmjiJcybf6vVr235sxx1RBxuvgtJZPJhhXKH86s8LlH01iXpfXqQ0GbOXQLESf-5VXwnv2hlhgzAF_hbXXqDqE3rX2wLT1B2PFOqZ8BftkfWC6Ll7IXDOfht4QbWnzPHw4KUrssnTcSbxsreWhCDV1DqtR38VHeNDtG73MhNY0zXMBIUPy2-9pwjsxFyoMQtUFOKKuBxzEhBpK8&state=Wxqa436p455F

Django Version: 1.6b3
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.webdesign',
 'django.contrib.sitemaps',
 'django.contrib.redirects',
 'south',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'users',
)
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware')


Traceback:
File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  201.                 response = middleware_method(request, response)
File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
  38.                     request.session.save()
File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
  57.             session_data=self.encode(self._get_session(no_load=must_create)),
File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in encode
  87.         serialized = self.serializer().dumps(session_dict)
File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/signing.py" in dumps
  88.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/usr/lib/python2.7/json/__init__.py" in dumps
  238.         **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py" in encode
  201.         chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py" in iterencode
  264.         return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py" in default
  178.         raise TypeError(repr(o) + " is not JSON serializable")

Exception Type: TypeError at /accounts/facebook/login/callback/
Exception Value: <allauth.socialaccount.models.SocialLogin object at 0xb4d0bf4c> is not JSON serializable

Let me know if further information is required.

Edit: Perhaps this is related? http://stackoverflow.com/questions/12553599/create-json-reponse-in-django-with-model

Edit 2: Another thought - I have a custom User model with no username field, only email. Here are my related allauth settings and User model:

# settings.py:
AUTH_USER_MODEL = 'users.User'

ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False
SOCIALACCOUNT_QUERY_EMAIL = False
SOCIALACCOUNT_EMAIL_REQUIRED = True


# users/models.py:

class User(AbstractBaseUser):
    email = models.EmailField(max_length=1024, unique=True, db_index=True)
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)

    is_active = models.BooleanField(default=True)
    is_verified = models.BooleanField(default=False)
    is_admin = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
@pennersr
Owner

This is due to:

https://docs.djangoproject.com/en/dev/releases/1.6/#default-session-serialization-switched-to-json

As a workaround you can switch the session serializer back to pickle:

https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_SERIALIZER

Ofcourse, this will be fixed in allauth...

@jaddison

Thank you for the tip!

@pennersr pennersr closed this in 939fd14 Sep 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment