Repository: zulip/zulip

Issue:
requirements: Upgrade python-social-auth to latest version
Upgrading python-social-auth (requirements/py2_socialauth.txt, requirements/py3_socialauth.txt) directly to the latest version should break the code. So you may have to make some changes in the codebase or add some extra dependencies for upgrading.


Discussion:
I'm working on this
@sinwar Cool. You should take a look at this link then. https://github.com/omab/python-social-auth/blob/master/MIGRATING_TO_SOCIAL.md

Resolving patch:
diff --git a/zproject/backends.py b/zproject/backends.py
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -17,9 +17,9 @@
 
 from apiclient.sample_tools import client as googleapiclient
 from oauth2client.crypt import AppIdentityError
-from social.backends.github import GithubOAuth2, GithubOrganizationOAuth2, \
+from social_core.backends.github import GithubOAuth2, GithubOrganizationOAuth2, \
     GithubTeamOAuth2
-from social.exceptions import AuthFailed
+from social_core.exceptions import AuthFailed
 from django.contrib.auth import authenticate
 from zerver.lib.utils import check_subdomain, get_subdomain
 
diff --git a/zproject/settings.py b/zproject/settings.py
--- a/zproject/settings.py
+++ b/zproject/settings.py
@@ -350,7 +350,7 @@ def get_secret(key):
     'guardian',
     'pipeline',
     'zerver',
-    'social.apps.django_app.default',
+    'social_django',
 ]
 if USING_PGROONGA:
     INSTALLED_APPS += ['pgroonga']
diff --git a/zproject/urls.py b/zproject/urls.py
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -384,7 +384,7 @@
 ]
 
 # Python Social Auth
-urls += [url(r'^', include('social.apps.django_app.urls', namespace='social'))]
+urls += [url(r'^', include('social_django.urls', namespace='social'))]
 
 # User documentation site
 urls += [url(r'^help/(?P<article>.*)$', HelpView.as_view(template_name='zerver/help/main.html'))]


Test patch:
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -36,10 +36,10 @@
 
 from zerver.views.auth import maybe_send_to_registration
 
-from social.exceptions import AuthFailed
-from social.strategies.django_strategy import DjangoStrategy
-from social.storage.django_orm import BaseDjangoStorage
-from social.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
+from social_core.exceptions import AuthFailed
+from social_django.strategy import DjangoStrategy
+from social_django.storage import BaseDjangoStorage
+from social_core.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
     GithubOAuth2
 
 from six.moves import urllib
@@ -359,7 +359,7 @@ def test_full_name_with_missing_key(self):
 
     def test_github_backend_do_auth_without_subdomains(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                         side_effect=self.do_auth), \
                 mock.patch('zerver.views.auth.login'):
             response = dict(email=self.email, name=self.name)
@@ -368,7 +368,7 @@ def test_github_backend_do_auth_without_subdomains(self):
 
     def test_github_backend_do_auth_with_non_existing_subdomain(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                         side_effect=self.do_auth):
             with self.settings(REALMS_HAVE_SUBDOMAINS=True):
                 self.backend.strategy.session_set('subdomain', 'test')
@@ -378,7 +378,7 @@ def test_github_backend_do_auth_with_non_existing_subdomain(self):
 
     def test_github_backend_do_auth_with_subdomains(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                         side_effect=self.do_auth):
             with self.settings(REALMS_HAVE_SUBDOMAINS=True):
                 self.backend.strategy.session_set('subdomain', 'zulip')
@@ -388,7 +388,7 @@ def test_github_backend_do_auth_with_subdomains(self):
 
     def test_github_backend_do_auth_for_default(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                         side_effect=self.do_auth), \
                 mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
             response = dict(email=self.email, name=self.name)
@@ -401,7 +401,7 @@ def test_github_backend_do_auth_for_default(self):
 
     def test_github_backend_do_auth_for_team(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubTeamOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubTeamOAuth2.do_auth',
                         side_effect=self.do_auth), \
                 mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
             response = dict(email=self.email, name=self.name)
@@ -415,7 +415,7 @@ def test_github_backend_do_auth_for_team(self):
 
     def test_github_backend_do_auth_for_team_auth_failed(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubTeamOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubTeamOAuth2.do_auth',
                         side_effect=AuthFailed('Not found')), \
                 mock.patch('logging.info'), \
                 mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
@@ -429,7 +429,7 @@ def test_github_backend_do_auth_for_team_auth_failed(self):
 
     def test_github_backend_do_auth_for_org(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOrganizationOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOrganizationOAuth2.do_auth',
                         side_effect=self.do_auth), \
                 mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
             response = dict(email=self.email, name=self.name)
@@ -443,7 +443,7 @@ def test_github_backend_do_auth_for_org(self):
 
     def test_github_backend_do_auth_for_org_auth_failed(self):
         # type: () -> None
-        with mock.patch('social.backends.github.GithubOrganizationOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOrganizationOAuth2.do_auth',
                         side_effect=AuthFailed('Not found')), \
                 mock.patch('logging.info'), \
                 mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
@@ -474,7 +474,7 @@ def do_auth_inactive(*args, **kwargs):
             return self.user_profile
 
         with mock.patch('zerver.views.auth.login_or_register_remote_user') as result, \
-                mock.patch('social.backends.github.GithubOAuth2.do_auth',
+                mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                            side_effect=do_auth_inactive):
             response = dict(email=self.email, name=self.name)
             user = self.backend.do_auth(response=response)
@@ -495,7 +495,7 @@ def do_auth(*args, **kwargs):
             return_data['valid_attestation'] = True
             return None
 
-        with mock.patch('social.backends.github.GithubOAuth2.do_auth',
+        with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
                         side_effect=do_auth):
             response = dict(email='nonexisting@phantom.com', name='Ghost')
             result = self.backend.do_auth(response=response)