-
Notifications
You must be signed in to change notification settings - Fork 682
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
fix: Avoid DoesNotExist exception in TokenRefreshSerializer #861
base: master
Are you sure you want to change the base?
fix: Avoid DoesNotExist exception in TokenRefreshSerializer #861
Conversation
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.
Looks good to me, thank you for the contribution!
I added this PR on a checklist for next major release since it does some breaking changes: #871
user = ( | ||
get_user_model() | ||
.objects.filter(**{api_settings.USER_ID_FIELD: user_id}) | ||
.first() |
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.
this may not be expected since the USER_AUTHENTICATION_RULE
expects a user object, not None
def default_user_authentication_rule(user: AuthUser) -> bool: |
suggestion: simply check if the user exists OR check authentication rule does not pass rather than solely rely on the authentication rule
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 the USER_AUTHENTICATION_RULE
method already performs the user is not None
check, would adding another check outside the method introduce unnecessary code duplication?
return user is not None and ( |
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.
yea, the problem is the initial typing was typed assuming the user object is valid...
I mean that's my fault for not checking that. I guess this is fine, but we should also update the typing for the authentication rule?
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.
Makes sense, updated
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.
awesome thank you!
#860
For deleted users, they should be treated the same as when no active user is found. This
DoesNotExist
exception was introduced in the previous version.