]> git.parisson.com Git - django-social-auth.git/commitdiff
Use filter instead of get to avoid 'Multiple objects returned' error. Closes gh-52
authorMatías Aguirre <matiasaguirre@gmail.com>
Wed, 4 May 2011 21:23:48 +0000 (18:23 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Wed, 4 May 2011 21:23:48 +0000 (18:23 -0300)
social_auth/views.py

index 6c446ff30c044d8aa6a22b564ff74bf917dc9c85..23fcb63b9678fd195d35ce497477d975bde96f15 100644 (file)
@@ -47,9 +47,11 @@ def complete_process(request, backend):
         login(request, user)
         if getattr(settings, 'SOCIAL_AUTH_SESSION_EXPIRATION', True):
             # Set session expiration date if present and not disabled by
-            # setting
+            # setting. Use last social-auth instance for current provider,
+            # users can associate several accounts with a same provider.
             backend_name = backend.AUTH_BACKEND.name
-            social_user = user.social_auth.get(provider=backend_name)
+            social_user = user.social_auth.filter(provider=backend_name) \
+                                          .order_by('-id')[0]
             if social_user.expiration_delta():
                 request.session.set_expiry(social_user.expiration_delta())
         url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT