From 384f3a02407de2f35886ebed0ef9ae2b511965b8 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 10 Nov 2016 15:41:36 +0000 Subject: [PATCH] Invalidate any existing prefetch cache on PUT requests. --- rest_framework/mixins.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 47a4923a1..f3695e665 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -71,9 +71,8 @@ class UpdateModelMixin(object): if getattr(instance, '_prefetched_objects_cache', None): # If 'prefetch_related' has been applied to a queryset, we need to - # refresh the instance from the database. - instance = self.get_object() - serializer = self.get_serializer(instance) + # forcibly invalidate the prefetch cache on the instance. + instance._prefetched_objects_cache = {} return Response(serializer.data)