Hello,

In a ModelViewset, a *prefetch_related* is set with an extra "order_by" :

def filter_queryset(self, qs):
    qs = super().filter_queryset(qs)
    qs = qs.prefetch_related(
        Prefetch(
            "related_data",
            queryset=Record.objects.order_by(
                "ts_update"
            ),
        ),
    )
    return qs

It is well applied on DRF *retrieve* operation. But on an *update*, after 
the changes have been applied, this prefetch_related is discarded 
<https://github.com/encode/django-rest-framework/blob/master/rest_framework/mixins.py#L70-L73>.
 
I completly understand why the cached data must be refreshed after the 
*perform_update*. But in the case here, it also removes the semantic 
meaning of the query, leading to the resulting data differs between a PUT 
and a later GET calls.

I cannot act in the *perform_update* method since the invalidation comes 
after and the only workaround I can think of is :

def update(self, request, *args, **kwargs):
        super().update(request, args, kwargs)
        return self.retrieve(request)

But that doesn't feel right, replacing the response of a base method by the 
one from an other. Could it be done differently ?

Cheers,

-- 
Clément Hallet

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/a151e1f4-51ac-451c-8d9a-9c077a603208%40googlegroups.com.

Reply via email to