From a4f932ed537267a3070a02753239d4a45b882407 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Wed, 4 May 2011 18:23:48 -0300 Subject: [PATCH] Use filter instead of get to avoid 'Multiple objects returned' error. Closes gh-52 --- social_auth/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/social_auth/views.py b/social_auth/views.py index 6c446ff..23fcb63 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -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 -- 2.39.5