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. 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