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
AttributeError "object has no attribute 'pk'" if "request.user" is not a Django model #80
Comments
I'd probably have to do it this way: - user_id = request.user.pk
+ if hasattr(request.user, "pk"):
+ user_id = request.user.pk
+ else:
+ user_id = str(request.user) There is a subtle difference |
I might just have to prevent the crash and let the developers bind what they need using the signals. |
Not everyone in the same situation as you will want to bind the user like you suggested. |
Fully agree. My suggestion was just the simplest fix that I could think of. Just keeping the |
fixed in 3.0.1 |
In my Django application, users are not (always) associated with a model. In this case, I get an
AttributeError
indjango_structlog/middlewares/request.py#L108
because therequest.user
does not have an attributepk
.A possible solution would be to use the
pk
attribute if it exists and otherwise just take thestr
of theuser
:The text was updated successfully, but these errors were encountered: