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

Fix for 'NoneType' object has no attribute 'is_anonymous' #76

Open
lgellert opened this issue Nov 2, 2021 · 0 comments
Open

Fix for 'NoneType' object has no attribute 'is_anonymous' #76

lgellert opened this issue Nov 2, 2021 · 0 comments

Comments

@lgellert
Copy link

lgellert commented Nov 2, 2021

With LoggingMixin set on my ViewSet, if an anonymous user hits an endpoint, drf_api_tracking throws an error:

'NoneType' object has no attribute 'is_anonymous'

It comes from BaseLoggingMixin._get_user(), specifically the line where it does if user.is_anonymous: since user is None in this case it fails.

A temporary work around for now is to do a monkey patch like so:

# monkey patch a bug in rest_framework_tracking
def fixed_get_user(self, request):
    user = request.user
    if not user or user.is_anonymous:
        return None
    return user

BaseLoggingMixin._get_user = fixed_get_user
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

No branches or pull requests

1 participant