st4lk / django-rest-social-auth

OAuth signin with django rest framework
MIT License
519 stars 122 forks source link

associate_user pipeline raise django.db.utils.IntegrityError #174

Open Elabbasy00 opened 1 year ago

Elabbasy00 commented 1 year ago
django.db.utils.IntegrityError: insert or update on table "social_auth_usersocialauth" violates foreign key constraint "social_auth_usersocialauth_user_id_17d28448_fk_accounts_user_id"
DETAIL:  Key (user_id)=(59) is not present in table "accounts_user".

Settings.py

SOCIAL_AUTH_FACEBOOK_KEY = '<Token>'

SOCIAL_AUTH_FACEBOOK_SECRET = '<Token>'

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email',]  # optional

SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': ','.join([
        # public_profile
        'id',  'name', 'first_name', 'last_name', 'age_range', 'link',
        'gender', 'locale', 'picture', 'timezone', 'updated_time', 'verified',
        # extra fields
        'email',
    ]),
}

AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

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',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

Custom User inherited from AbstractUser

   username = models.CharField(max_length=150, unique=True, validators=[RegexValidator(
        regex=USERNAME_REGEX,  code='invalid_username')])
    email = models.EmailField(_('email address'), null=True, blank=True)

with this error also same user created every request