0

I am using python social auth for signup an login

urls i am using for signup

<a href= '/login/google-oauth2/'>Signup with Google</a><br/>
<a href= '/login/linkedin/'>Signup with Linkedin</a>

First time user is getting signed up. User is getting created also. Next time when i am clicking on same url i am getting the following error

duplicate key value violates unique constraint "people_userprofile_user_id_key"
DETAIL:  Key (user_id)=(211) already exists.

SOCIAL_AUTH_PIPELINE = (

    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.mail.mail_validation',
    'social.pipeline.social_auth.associate_by_email',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.debug.debug',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'people.pipeline.custom_pipeline',


)

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper
  54.             return func(request, backend, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py" in complete
  28.                        redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/actions.py" in do_complete
  43.         user = backend.complete(user=user, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in complete
  40.         return self.auth_complete(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in wrapper
  202.             return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/oauth.py" in auth_complete
  382.                             *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in wrapper
  202.             return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/oauth.py" in do_auth
  391.         return self.strategy.authenticate(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/strategies/django_strategy.py" in authenticate
  76.         return authenticate(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py" in authenticate
  49.             user = backend.authenticate(**credentials)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in authenticate
  81.         return self.pipeline(pipeline, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in pipeline
  84.         out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in run_pipeline
  111.             result = func(*args, **out) or {}
File "/home/gaurav/PycharmProjects/ezvsa/people/pipeline.py" in custom_pipeline
  28.         user_pro.save()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save
  545.                        force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save_base
  573.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in _save_table
  654.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in _do_insert
  687.                                using=using, raw=raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py" in _insert
  232.         return insert_query(self.model, objs, fields, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in insert_query
  1511.     return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  898.             cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/panels/sql/tracking.py" in execute
  159.         return self._record(self.cursor.execute, sql, params)
File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/panels/sql/tracking.py" in _record
  101.             return method(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py" in __exit__
  99.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /complete/google-oauth2/
Exception Value: duplicate key value violates unique constraint "people_userprofile_user_id_key"
DETAIL:  Key (user_id)=(211) already exists.

I dont know what wrong i am doing. After user got registered, its again trying to register that user instead of login

Wagh
  • 4,202
  • 5
  • 39
  • 62
  • Can you share your DEFAULT_AUTH_PIPELINE? – Ajai May 21 '15 at 12:36
  • what does 'people.pipeline.require_email' do? Can you share your code? – Ajai May 21 '15 at 12:49
  • This not having any use i removed it. It was just for checking weather i am getting user email or not – Wagh May 21 '15 at 12:53
  • @Gaurav, can you post your model too please. I suspect you got this error becuase for some reason python-social-auth is trying to create a user every time instead of logging in after first registration. – Jahongir Rahmonov May 28 '15 at 12:16
  • Thank you for your response. But i got the solution. There was mistake in custom pipeline ""/home/gaurav/PycharmProjects/ezvsa/people/pipeline.py" in custom_pipeline" – Wagh May 28 '15 at 12:57

0 Answers0