-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Highlight select_related
and prefetch_related
usage.
#1977
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
Comments
select_related
and prefetch_related
in generic views / serializers.select_related
and prefetch_related
usage.
select_related
and prefetch_related
usage.select_related
and prefetch_related
usage.
I note this issue is still open. Does that imply that the documentation improvements have yet to be made? |
As far as I can tell, someone needs to step up and do the work (tm) |
I'm going to throw a note down here for whoever ends up doing this ticket: |
@kevin-brown > Or at least the prefetched objects associated with the instance should not be modified. Referencing #4553 here, as it fixes the issue (though is an unsatisfactory way imho). |
I had issues described in #2442 with OneToOne relation using It would be worth mentioning in documentation. I didn't expect this behaviour and it was not that simple to debug. |
I'm going to de-milestone this. We'll reassess after v3.7. |
Hi @johnthagen. Good set of links.
I'm not sure there is a solution, in the sense of anything that will do this automatically for you. Bottom line is you need to look at the queries performed by each end point and carefully optimise them. I'm not entirely convinced this is an actionable issue. (Other than adding some links back to Django's docs maybe.) It's a good topic for blog posts. |
Yeah I tend to agree that there isn't something automatic, but I think that examples / some discussion can go a long way. The issue with only using blog posts is they become stale / out-of-date. Having official docs allows people to contribute / keep the information up to date. The caching docs seem to be set up in a way I was imagining: It has a concrete example and some discussion. |
it would be great if you come up with a PR |
IMHO it's more of a Django ORM good practices with DRF. what if modifying some examples using the aforementioned possible current good practices? |
Hello everyone, We faced the same issues in some projects and I have created a simple package to use in our projects. Then I have decided to publish it in github and pypi for anyone who is interested. Btw it is still being tested and there might be bugs. You can check it out on https://github.com/thetarby/django-auto-related Simply what it does: What django-rest gives us is the ability to know what will be accessed from the object before it is accessed by inspecting the source attribute of the fields defined in a serializer. Then it traces those sources back on django fields instances and translates them to For instance, If you have any feedback I would be glad to hear from you on github. |
great package! i checked the code and like it. will use in my projects in near future. |
Thank you. I am glad that you think that way. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bumping this issue to un-stale it, as I think this is an important topic for beginners that could be improved in the docs. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
can we close this based on #7610? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
In both the generic view and serializer sections we need to make sure we're pointing out appropriate usage of
select_related
/prefetch_related
. (To review: is there anything in there at the moment?)Also see #1976.
The text was updated successfully, but these errors were encountered: