social-app-django icon indicating copy to clipboard operation
social-app-django copied to clipboard

AttributeError: 'NoneType' object has no attribute 'provider'

Open bubublik opened this issue 5 years ago • 14 comments

When I try to signup via the social app(Twitter, Linkedin, etc. ) I got an error: AttributeError at /oauth/complete/linkedin-oauth2/ 'NoneType' object has no attribute 'provider' AttributeError at /oauth/complete/twitter/ 'NoneType' object has no attribute 'provider'

AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.linkedin.LinkedinOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.patreon.PatreonOAuth2',
    'accounts.backends.EmailModelBackend',
    'accounts.backends.CaseInsensitiveModelBackend',
    '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.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'accounts.helpers.social_pipeline.set_user_group',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)
Traceback (most recent call last):
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 63, in callback
    return old_callback(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 63, in callback
    return old_callback(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_django/utils.py", line 49, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_django/views.py", line 31, in complete
    return do_complete(request.backend, _do_login, user=request.user,
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_core/actions.py", line 73, in do_complete
    social_user.provider)
AttributeError: 'NoneType' object has no attribute 'provider'
ERROR    log	Internal Server Error: /oauth/complete/linkedin-oauth2/
Traceback (most recent call last):
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 63, in callback
    return old_callback(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 63, in callback
    return old_callback(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_django/utils.py", line 49, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_django/views.py", line 31, in complete
    return do_complete(request.backend, _do_login, user=request.user,
  File "/Users/whs/.local/share/virtualenvs/wh/lib/python3.8/site-packages/social_core/actions.py", line 73, in do_complete
    social_user.provider)

bubublik avatar Oct 03 '20 12:10 bubublik

hmm.. user was created, but not associated with user_social_auths

bubublik avatar Oct 03 '20 13:10 bubublik

associate_user() got exception:

null value in column "extra_data" violates not-null constraint
DETAIL:  Failing row contains (144, linkedin-oauth2, SDCsN4sdfdAP, null, 341, 2020-10-03 13:16:06.24929+00, 2020-10-03 13:16:06.249332+00).

bubublik avatar Oct 03 '20 13:10 bubublik

We at the NLM are seeing this as well. I have a package that provides a customized version of the Cognito backend which knows our conventions and can do some extra things - like allow Google user to create accounts, but insist that Staff accounts already exist (pipeline).

In our testing, we are using Django 2.2.x where x ranges from 13 to 16, and social-auth-core 3.2.0 with social_auth_django 3.1.0. We do not see it in a more recent version. It seems to have something to do with database backend - with sqlite3 it seems not to happen, with PostgreSQL it does.

For us, the specific constraint violation is different:

psycopg2.errors.NotNullViolation: null value in column "created" violates not-null constraint
DETAIL:  Failing row contains (45, nihlogin, NIH-Siteminder_davisda4, {}, 7, null, null).

https://github.com/python-social-auth/social-app-django/blob/877fe4611c2e0522b020d38f5aed385a19b854ea/social_django/models.py#L38

But it looks like the social_django.storage.DjangoUserMixin is not providing values for any of these fields in the 'create_social_auth` method.

I will now check the latest code for social-auth-app-django.

danizen avatar Oct 28 '20 18:10 danizen

Is there a solution for this? I'm still facing the issue. I'm using google-auth 1.11.0 and django 3.0.5

balajeeraman avatar Mar 01 '21 18:03 balajeeraman

I have the same problem after the login by GoogleOauth2.

My pipeline:

SOCIAL_AUTH_PIPELINE = [  # Note: Sequence of functions matters here.
    '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.social_auth.associate_by_email',
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
]

My authentication backends:

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

telefonosuci avatar Mar 07 '21 20:03 telefonosuci

I was able to solve it by upgrading the package to latest!

On Sun, Mar 7, 2021 at 2:49 PM SUCI [email protected] wrote:

I have the same problem after the login by GoogleOauth2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-social-auth/social-app-django/issues/284#issuecomment-792350188, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFS4TXI7PASH5TUZDAGUUGTTCPRFLANCNFSM4SCUAAQA .

-- Regards,

Balajee Venkataraman

balajeeraman avatar Mar 08 '21 20:03 balajeeraman

which one do u upgrade for which version as well? @balajeeraman

krastykovyaz avatar Apr 17 '21 16:04 krastykovyaz

I don’t remember, but I updated the OAuth to the latest!

On 17-Apr-2021, at 11:56 AM, Aleksandr @.***> wrote:

which one do u upgrade for which version as well?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-social-auth/social-app-django/issues/284#issuecomment-821853416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFS4TXP3XBANY7YHN6A62KTTJG4UNANCNFSM4SCUAAQA.

balajeeraman avatar Apr 17 '21 18:04 balajeeraman

AttributeError at /auth/complete/google-oauth2/ 'NoneType' object has no attribute 'provider'

I'm still facing the issue with Gmail login in production environment, but the same code is working fine in development environment. Can anyone tell the reason for this issue ?

AUTHENTICATION_BACKENDS = (
 'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
 'social_core.backends.google.GoogleOpenId',  # for Google authentication
 'social_core.backends.google.GoogleOAuth2',  # for Google authentication
 'django.contrib.auth.backends.ModelBackend',
)

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.sessions',
    'social_django',
    'sslserver'
]

monicama avatar Nov 17 '21 09:11 monicama

I have had the same issue in the production. I didn’t fix that one. If u solve the problem let me know plz. I have done an auth just by email. peredam.su Wednesday, November 17, 2021, 12:35 PM +0300 from @.*** @.***>:

AttributeError at /auth/complete/google-oauth2/ 'NoneType' object has no attribute 'provider' I'm still facing the issue with Gmail login in production environment, but the same code is working fine in development environment. Can anyone tell the reason for this issue ? AUTHENTICATION_BACKENDS = ( 'social_core.backends.open_id.OpenIdAuth', # for Google authentication 'social_core.backends.google.GoogleOpenId', # for Google authentication 'social_core.backends.google.GoogleOAuth2', # for Google authentication 'django.contrib.auth.backends.ModelBackend', )

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_SSL_REDIRECT = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True

INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.sessions', 'social_django', 'sslserver' ]

— You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe . Triage notifications on the go with GitHub Mobile for iOS or Android .

krastykovyaz avatar Nov 17 '21 13:11 krastykovyaz

Please check the versions across your dev and prod environments and make sure they match. Hopefully, that should solve the issue!

balajeeraman avatar Nov 17 '21 15:11 balajeeraman

@balajeeraman Yes the versions is mismatched, So I have updated it. Thank you

@krastykovyaz I have update the following plugins with specified version and issue was fixed for me pip install social-auth-app-django==4.0.0 pip install social-auth-core==3.3.3

monicama avatar Nov 18 '21 06:11 monicama

Thank u so much 😊 

Thursday, November 18, 2021, 9:27 AM +0300 from @.*** @.>: @.

Yes the versions is mismatched, So I have updated it. Thank you @.*** I have update the following plugins with specified version and issue was fixed for me pip install social-auth-app-django==4.0.0 pip install social-auth-core==3.3.3 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub , or unsubscribe . Triage notifications on the go with GitHub Mobile for iOS or Android .

krastykovyaz avatar Nov 18 '21 06:11 krastykovyaz

@monicama thanks a lot, this work 🎉

izabelajelonek avatar Dec 08 '21 10:12 izabelajelonek