Skip to content

Conversation

@zaslavskii
Copy link
Contributor

Description

When using nplusone middleware from https://github.com/jmcarp/nplusone, the error occurs if one tries to access Token app in django admin.

This happens due to recursive DB calls, as the user id is accessed through the user object rather than through user_id field.

Not sure if it's a problem of DRF itself, but the following change fixes the problem as well as reduces DB hits.

image

jmcarp/nplusone#38

@lovelydinosaur
Copy link
Contributor

Okay, I actually had to look this up in the note here... https://docs.djangoproject.com/en/3.1/topics/db/models/#field-name-hiding-is-not-permitted

Some fields define extra attributes on the model, e.g. a ForeignKey defines an extra attribute with _id appended to the field name, as well as related_name and related_query_name on the foreign model.

Do the Django docs mention the <field>_id attribute elsewhere, or only in that passing note?

@zaslavskii
Copy link
Contributor Author

@lovelydinosaur
Copy link
Contributor

Right, makes sense. Thanks!

@lovelydinosaur lovelydinosaur merged commit b25ac6c into encode:master Mar 19, 2021
@zaslavskii zaslavskii deleted the bug/dont-hit-db-when-accessing-user-id-from-token-proxy branch March 19, 2021 13:22
stefanacin pushed a commit to stefanacin/django-rest-framework that referenced this pull request Mar 22, 2021
@lovelydinosaur lovelydinosaur mentioned this pull request Mar 25, 2021
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
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

Successfully merging this pull request may close these issues.

2 participants