`use_query` does not properly pre-fetch some model fields
Archmonger opened this issue · 3 comments
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.
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.
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.
Looks like prefect_related_objects was exactly what we needed.