GeeWee / django-auto-prefetching

Automatic prefetching for Django
MIT License
231 stars 18 forks source link

Prefetch when returning nested object from POST #14

Closed johnthagen closed 4 years ago

johnthagen commented 4 years ago

I've seen an issue where if a large nested object is POSTed to the server, the WritableNestedSerializer returns the instance it created from create() and then that object is fetched without select_related or prefetch_related applied to it.

Using AutoPrefetchViewSetMixin, the GET requests are all prefetched correctly but responses from POSTs are not. Is this something within scope for this project or is there some other kind of work around?

GeeWee commented 4 years ago

Hm. I'm not sure if it's within scope. If you serialize it via a Serializer, you might be able to fetch it by calling prefetch directly and giving it a Queryset and a serializer. That should perform all of the correct prefetches. The new docs might show you how to do that.

If you have a specific object you need to serialize though, aka not a queryset there's no way to do that right now.

johnthagen commented 4 years ago

After some more digging, I believe I found that I was interpreting the results from django-debug-toolbar incorrectly, and this is actually not an issue.