0

I am trying to login through google in my django application . I am getting some integrity error while trying to save the user.

The error is -

IntegrityError at /auth/complete/google-oauth2/ duplicate key value violates unique constraint "pd_user_master_user_id_key" DETAIL: Key (user_id)=(55) already exists

This is the function i'm using to save a default profile of the user through it's ID in the User Profile Model. -

def save_profile(backend, user, response, *args, **kwargs):
    profile = UserProfile(user_id=user.id)
    #print(request.user.id)
    profile.contact_no=1234567890
    profile.department=1
    profile.status=0 
    profile.save() 
    return {"profile": profile}

And this is the Pipeline as recommended -

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.user.create_user',
    'pd.views.Users.save_profile', # <--- set the path to the function
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

In DB, a user is created in the auth_user table, but no object created in social_auth_usersocialauth table and no profile created for the same.

Can anyone clear this out what is happening behind the scenes ?

ParfectShot
  • 123
  • 2
  • 12

0 Answers0