Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading Django user models before apps are ready #3386

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions allauth/socialaccount/providers/base/provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.core.exceptions import ImproperlyConfigured

from allauth.account.models import EmailAddress
from allauth.socialaccount import app_settings
from allauth.socialaccount.adapter import get_adapter


class ProviderException(Exception):
Expand Down Expand Up @@ -59,6 +57,7 @@ def sociallogin_from_response(self, request, response):
:return: A populated instance of the `SocialLogin` model (unsaved).
"""
# NOTE: Avoid loading models at top due to registry boot...
from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.models import SocialAccount, SocialLogin

adapter = get_adapter(request)
Expand Down Expand Up @@ -123,6 +122,9 @@ def extract_common_fields(self, data):
return {}

def cleanup_email_addresses(self, email, addresses, email_verified=False):
# Avoid loading models before adapters have been registered.
from allauth.account.models import EmailAddress

# Move user.email over to EmailAddress
if email and email.lower() not in [a.email.lower() for a in addresses]:
addresses.append(
Expand Down