CurrentUserDefault doesn't work with AnonymousUser #8645
Unanswered
goliney
asked this question in
Question & Answer
Replies: 1 comment
-
Why don't we modify CurrentUserDefault code like below? class CurrentUserDefault:
requires_context = True
def __call__(self, serializer_field):
user = serializer_field.context['request'].user
if isinstance(user, AnonymousUser):
return None
return user
def __repr__(self):
return '%s()' % self.__class__.__name__ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use
CurrentUserDefault
with a field that can be null:Everything works fine when a user is logged in. However, if a user is not authenticated I get this:
Is there a reason why
CurrentUserDefault
doesn't work with anonymous users?P.S. I know I can use this instead of CurrentUserDefault and it will work:
P.S.S. I duplicated this question to Stack Overflow
Beta Was this translation helpful? Give feedback.
All reactions