-
Notifications
You must be signed in to change notification settings - Fork 678
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
base: master
Are you sure you want to change the base?
Conversation
@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? |
Running into this same issue. Any updates? |
@@ -3,6 +3,5 @@ | |||
from .backends import TokenBackend | |||
from .settings import api_settings | |||
|
|||
User = get_user_model() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
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.