[PATCH] REST: Only call prefetch_related from a method

Stephen Finucane stephen at that.guru
Wed Feb 8 09:11:24 AEDT 2017


Calling prefetch_related on a class-level queryset variable doesn't do
anything and is a mistake. Correct this.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Cc: Andy Doan <andy.doan at linaro.org>
---
 patchwork/api/check.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index dcdc5c5..393fcf2 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -88,10 +88,12 @@ class CheckSerializer(HyperlinkedModelSerializer):
 
 class CheckMixin(object):
 
-    queryset = Check.objects.prefetch_related('patch', 'user')
     serializer_class = CheckSerializer
     filter_class = CheckFilter
 
+    def get_queryset(self):
+        return Check.objects.prefetch_related('patch', 'user')
+
 
 class CheckListCreate(CheckMixin, ListCreateAPIView):
     """List or create checks."""
-- 
2.9.3



More information about the Patchwork mailing list