python-social-auth / social-app-django-mongoengine

Python Social Auth - Application - Django - Mongoengine Storage
BSD 3-Clause "New" or "Revised" License
7 stars 5 forks source link

TypeError: __init__() missing 1 required positional argument: 'strategy' #2

Open stephenomalley opened 6 years ago

stephenomalley commented 6 years ago

Not sure what I've done wrong, but in our app we get the error TypeError: __init__() missing 1 required positional argument: 'strategy' when running tests. It happens for the first test and seems to be caused by the __init__ method not being patched. It seems to only effect the first test run in our suite as on later tests the __init__ method is patched.

If we add from social_django import views in the __init__.py of our project root then the error doesn't appear. If we remove any social_core backends from out AUTHENTICATION_BACKENDS list then the error doesn't occur. So the issue has a workaround, but I'm just wondering if there is something wrong with our set up.

Here are our versions: Django==1.11.10 social-auth-app-django==2.1.0 social-auth-app-django-mongoengine==1.0.0 social-auth-core==1.7.0 social-auth-storage-mongoengine==1.0.1

Python 3.6.4

Our settings.py has the following setup:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
    'social_django_mongoengine',
   ...
)
AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
   ...
)
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_PATH],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                "django.contrib.auth.context_processors.auth",
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
            "debug": DEBUG,

        }
    }
]

Full Stack trace of error:

Error
Traceback (most recent call last):
  File ".../unittest/case.py", line 58, in testPartExecutor
    yield
  File ".../unittest/case.py", line 600, in run
    testMethod()
  File ".../site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File ".../site-packages/django/test/utils.py", line 384, in inner
    return func(*args, **kwargs)
  File "...acceptance/tests.py", line 152, in test_access_revoked_request_study_list_denied
    self.client.login(**self.creds)
  File ".../django/test/client.py", line 628, in login
    user = authenticate(**credentials)
  File ".../site-packages/django/contrib/auth/__init__.py", line 68, in authenticate
    for backend, backend_path in _get_backends(return_tuples=True):
  File "/home/stephen/projects/prolific_python_3/lib/python3.5/site-packages/django/contrib/auth/__init__.py", line 29, in _get_backends
    backend = load_backend(backend_path)
  File ".../site-packages/django/contrib/auth/__init__.py", line 23, in load_backend
    return import_string(path)()
Exception: __init__() missing 1 required positional argument: 'strategy'
lcmencia commented 6 years ago

AUTHENTICATION_BACKENDS = ( 'social.backends.facebook.FacebookOAuth2', )

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [TEMPLATE_PATH], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'social.apps.django_app.context_processors.backends', 'social.apps.django_app.context_processors.login_redirect', ], }, }, ]

matmsa27 commented 5 years ago

I have the same problem

govindsharma7 commented 5 years ago

You using social_core.backends.facebook.FacebookOAuth2 in AUTHENTICATION_BACKENDS, for this you have to put social_django in INSTALLED_APPS.

If you put this issue will be resolved.

NeoXtreme commented 5 years ago

You using social_core.backends.facebook.FacebookOAuth2 in AUTHENTICATION_BACKENDS, for this you have to put social_django in INSTALLED_APPS.

If you put this issue will be resolved.

Perfect! I had removed social_django but forgot to remove entries from AUTHENTICATION_BACKENDS.