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

This is an attempt at fixing AppRegistryNotReady #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olymk2
Copy link

@olymk2 olymk2 commented Nov 14, 2019

This issue seems to only arise when using multiple drf extensions, I found this related issues.

apragacz/django-rest-registration#36
https://github.com/encode/django-rest-framework/issues/6478

I hit the issue when using rest_flex_fields commenting it out temporarily fixes the issue, it only occurs when both are present similar to django-rest-registration.

Basically it related to the user model being used inside modules so they are called before django is ready.

@bjxu
Copy link

bjxu commented Mar 28, 2020

@davesque Hi do you think this fix could be merged anytime soon? If you think it's not an issue, how do you propose to solve the problem?

@bensonmyrtil
Copy link

Running into this same issue. Any updates?

@@ -3,6 +3,5 @@
from .backends import TokenBackend
from .settings import api_settings

User = get_user_model()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unused import statement for get_user_model

username_field = User.USERNAME_FIELD
user_model = get_user_model()

username_field = user_model.USERNAME_FIELD
Copy link
Member

@Andrew-Chen-Wang Andrew-Chen-Wang May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to set a name "user_model" if it's only used once in L23? Just use get_user_model().USERNAME_FIELD

@@ -1,9 +1,9 @@
from django.contrib.auth import get_user_model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine the import statements:
from django.contrib.auth import authenticate, get_user_model


def __init__(self, token):
self.token = token
from django.contrib.auth import models as auth_models
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is always used, it's best if the import is still left at the top for performance.

user = User.objects.get(**{api_settings.USER_ID_FIELD: user_id})
except User.DoesNotExist:
user = self.user_model.objects.get(**{api_settings.USER_ID_FIELD: user_id})
except self.user_model.DoesNotExist:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much rather see something above the class: User = get_user_model() than see what's being done here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants