Skip to content

use_query does not properly pre-fetch some model fields #110

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

Closed
Archmonger opened this issue Nov 15, 2022 · 3 comments · Fixed by #112
Closed

use_query does not properly pre-fetch some model fields #110

Archmonger opened this issue Nov 15, 2022 · 3 comments · Fixed by #112

Comments

@Archmonger
Copy link
Contributor

Archmonger commented Nov 15, 2022

Current Situation

ManyToMany fields are not properly prefetched, thus causing SynchronousOnlyOperation exceptions.

For example, in this case.

Proposed Actions

Determine why the current prefetch logic doesn't work on this use case.

@rmorshea
Copy link
Contributor

It looks like one-to-many and many-to-many relationships return relationship managers. Should be as simple as calling the get_queryset() and recursively resolving values.

@Archmonger Archmonger linked a pull request Nov 15, 2022 that will close this issue
3 tasks
@rmorshea
Copy link
Contributor

Ok, as discovered in that draft PR, get_queryset() does not actually cache anything. After doing a bit of research, it seems like this is something that needs to be managed by users with prefetch_related or select_related. There's a prefect_related_objects function that can work on model instances rather than queries, but I'm not really sure how that could be used automatically.

@Archmonger
Copy link
Contributor Author

Looks like prefect_related_objects was exactly what we needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants