diff --git a/social_django/storage.py b/social_django/storage.py index 2dd9b05a..d39d0e64 100644 --- a/social_django/storage.py +++ b/social_django/storage.py @@ -49,7 +49,7 @@ def user_exists(cls, *args, **kwargs): """ if 'username' in kwargs: kwargs[cls.username_field()] = kwargs.pop('username') - return cls.user_model().objects.filter(*args, **kwargs).exists() + return cls.user_model()._default_manager.filter(*args, **kwargs).exists() @classmethod def get_username(cls, user): @@ -76,15 +76,15 @@ def create_user(cls, *args, **kwargs): # stays undamaged by wrapping the create in an atomic. using = router.db_for_write(cls.user_model()) with transaction.atomic(using=using): - user = cls.user_model().objects.create_user(*args, **kwargs) + user = cls.user_model()._default_manager.create_user(*args, **kwargs) else: - user = cls.user_model().objects.create_user(*args, **kwargs) + user = cls.user_model()._default_manager.create_user(*args, **kwargs) except IntegrityError as exc: # If email comes in as None it won't get found in the get if kwargs.get('email', True) is None: kwargs['email'] = '' try: - user = cls.user_model().objects.get(*args, **kwargs) + user = cls.user_model()._default_manager.get(*args, **kwargs) except cls.user_model().DoesNotExist: raise exc return user @@ -94,7 +94,7 @@ def get_user(cls, pk=None, **kwargs): if pk: kwargs = {'pk': pk} try: - return cls.user_model().objects.get(**kwargs) + return cls.user_model()._default_manager.get(**kwargs) except cls.user_model().DoesNotExist: return None @@ -102,7 +102,7 @@ def get_user(cls, pk=None, **kwargs): def get_users_by_email(cls, email): user_model = cls.user_model() email_field = getattr(user_model, 'EMAIL_FIELD', 'email') - return user_model.objects.filter(**{email_field + '__iexact': email}) + return user_model._default_manager.filter(**{email_field + '__iexact': email}) @classmethod def get_social_auth(cls, provider, uid): diff --git a/social_django/strategy.py b/social_django/strategy.py index b17218e0..b460be57 100644 --- a/social_django/strategy.py +++ b/social_django/strategy.py @@ -147,7 +147,7 @@ def from_session_value(self, val): if isinstance(val, dict) and 'pk' in val and 'ctype' in val: ctype = ContentType.objects.get_for_id(val['ctype']) ModelClass = ctype.model_class() - val = ModelClass.objects.get(pk=val['pk']) + val = ModelClass._default_manager.get(pk=val['pk']) return val def get_language(self): diff --git a/tests/test_admin.py b/tests/test_admin.py index e4369194..f4efc08c 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -8,7 +8,7 @@ class SocialAdminTest(TestCase): @classmethod def setUpTestData(cls): User = get_user_model() - User.objects.create_superuser( + User._default_manager.create_superuser( username='admin', email='admin@test.com', first_name='Admin', password='super-duper-test' ) diff --git a/tests/test_models.py b/tests/test_models.py index 4adea6b4..2d6c8676 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -14,14 +14,14 @@ class TestSocialAuthUser(TestCase): def test_user_relationship_none(self): """Accessing User.social_user outside of the pipeline doesn't work""" User = get_user_model() - user = User.objects.create_user(username="randomtester") + user = User._default_manager.create_user(username="randomtester") with self.assertRaises(AttributeError): user.social_user def test_user_existing_relationship(self): """Accessing User.social_user outside of the pipeline doesn't work""" User = get_user_model() - user = User.objects.create_user(username="randomtester") + user = User._default_manager.create_user(username="randomtester") UserSocialAuth.objects.create(user=user, provider='my-provider', uid='1234') @@ -30,7 +30,7 @@ def test_user_existing_relationship(self): def test_get_social_auth(self): User = get_user_model() - user = User.objects.create_user(username="randomtester") + user = User._default_manager.create_user(username="randomtester") user_social = UserSocialAuth.objects.create(user=user, provider='my-provider', uid='1234') @@ -62,7 +62,7 @@ def test_cleanup(self): class TestUserSocialAuth(TestCase): def setUp(self): self.user_model = get_user_model() - self.user = self.user_model.objects.create_user( + self.user = self.user_model._default_manager.create_user( username='randomtester', email='user@example.com') self.usa = UserSocialAuth.objects.create( user=self.user, provider='my-provider', uid='1234') @@ -70,7 +70,7 @@ def setUp(self): def test_changed(self): self.user.email = eml = 'test@example.com' UserSocialAuth.changed(user=self.user) - db_eml = self.user_model.objects.get(username=self.user.username).email + db_eml = self.user_model._default_manager.get(username=self.user.username).email self.assertEqual(db_eml, eml) def test_set_extra_data(self): @@ -117,7 +117,7 @@ def test_create_user_custom_username(self, *args): @mock.patch('social_django.storage.transaction', spec=[]) def test_create_user_without_transaction_atomic(self, *args): UserSocialAuth.create_user(username='test') - self.assertTrue(self.user_model.objects.filter( + self.assertTrue(self.user_model._default_manager.filter( username='test').exists()) def test_get_user(self): diff --git a/tests/test_strategy.py b/tests/test_strategy.py index 8f9f3ae7..bb75cf1c 100644 --- a/tests/test_strategy.py +++ b/tests/test_strategy.py @@ -51,7 +51,7 @@ def test_random_string(self): def test_session_value(self): user_model = get_user_model() - user = user_model.objects.create_user(username="test") + user = user_model._default_manager.create_user(username="test") ctype = ContentType.objects.get_for_model(user_model) val = self.strategy.to_session_value(val=user) diff --git a/tests/test_views.py b/tests/test_views.py index ada6981d..08671877 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -39,7 +39,7 @@ def test_complete(self, mock_request): @mock.patch('social_core.backends.base.BaseAuth.request') def test_disconnect(self, mock_request): user_model = get_user_model() - user = user_model.objects.create_user(username='test', password='pwd') + user = user_model._default_manager.create_user(username='test', password='pwd') UserSocialAuth.objects.create(user=user, provider='facebook') self.client.login(username='test', password='pwd')