[PATCH v2 1/4] REST: Specify default ordering fields

Daniel Axtens dja at axtens.net
Fri Oct 20 16:36:53 AEDT 2017


From: Stephen Finucane <stephen at that.guru>

This hides warnings likes the following:

    UnorderedObjectListWarning: Pagination may yield inconsistent
    results with an unordered object_list: <QuerySet [<User:
    test_user_0>]>

Signed-off-by: Stephen Finucane <stephen at that.guru>
[dja: fix merge conflict in patch.py]
Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 patchwork/api/bundle.py  | 1 +
 patchwork/api/check.py   | 1 +
 patchwork/api/cover.py   | 1 +
 patchwork/api/event.py   | 5 ++---
 patchwork/api/patch.py   | 1 +
 patchwork/api/person.py  | 1 +
 patchwork/api/project.py | 1 +
 patchwork/api/series.py  | 1 +
 patchwork/api/user.py    | 1 +
 9 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/patchwork/api/bundle.py b/patchwork/api/bundle.py
index 92899566365e..0278592a9e34 100644
--- a/patchwork/api/bundle.py
+++ b/patchwork/api/bundle.py
@@ -76,6 +76,7 @@ class BundleList(BundleMixin, ListAPIView):
     filter_class = BundleFilter
     search_fields = ('name',)
     ordering_fields = ('id', 'name', 'owner')
+    ordering = 'id'
 
 
 class BundleDetail(BundleMixin, RetrieveAPIView):
diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index 66b460174e87..5b3815050664 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -81,6 +81,7 @@ class CheckListCreate(CheckMixin, ListCreateAPIView):
     """List or create checks."""
 
     lookup_url_kwarg = 'patch_id'
+    ordering = 'id'
 
     def create(self, request, patch_id, *args, **kwargs):
         p = Patch.objects.get(id=patch_id)
diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 5d829eba2f07..2a7651f488ae 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -75,6 +75,7 @@ class CoverLetterList(ListAPIView):
     filter_class = CoverLetterFilter
     search_fields = ('name',)
     ordering_fields = ('id', 'name', 'date', 'submitter')
+    ordering = 'id'
 
     def get_queryset(self):
         qs = CoverLetter.objects.all().prefetch_related('series')\
diff --git a/patchwork/api/event.py b/patchwork/api/event.py
index cc9270ae2ac9..0d97af227f0e 100644
--- a/patchwork/api/event.py
+++ b/patchwork/api/event.py
@@ -91,13 +91,12 @@ class EventList(ListAPIView):
     serializer_class = EventSerializer
     filter_class = EventFilter
     page_size_query_param = None  # fixed page size
-    ordering = '-date'
     ordering_fields = ()
+    ordering = '-date'
 
     def get_queryset(self):
         return Event.objects.all()\
             .select_related('project', 'patch', 'series', 'cover',
                             'previous_state', 'current_state',
                             'previous_delegate', 'current_delegate',
-                            'created_check')\
-            .order_by('-date')
+                            'created_check')
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 1f0ead1f799a..cb829c7db5d7 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -148,6 +148,7 @@ class PatchList(ListAPIView):
     search_fields = ('name',)
     ordering_fields = ('id', 'name', 'project', 'date', 'state', 'archived',
                        'submitter', 'check')
+    ordering = 'id'
 
     def get_queryset(self):
         # TODO(stephenfin): Does the defer here cause issues with Django 1.6
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index d002afff5d9f..326c117e2cf8 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -53,6 +53,7 @@ class PersonList(PersonMixin, ListAPIView):
 
     search_fields = ('name', 'email')
     ordering_fields = ('id', 'name', 'email')
+    ordering = 'id'
 
 
 class PersonDetail(PersonMixin, RetrieveAPIView):
diff --git a/patchwork/api/project.py b/patchwork/api/project.py
index 11d65049140d..446c47356951 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -79,6 +79,7 @@ class ProjectList(ProjectMixin, ListAPIView):
     search_fields = ('link_name', 'list_id', 'list_email', 'web_url',
                      'scm_url', 'webscm_url')
     ordering_fields = ('id', 'name', 'link_name', 'list_id')
+    ordering = 'id'
 
 
 class ProjectDetail(ProjectMixin, RetrieveUpdateAPIView):
diff --git a/patchwork/api/series.py b/patchwork/api/series.py
index 12f9277c882c..b5f4450a71b0 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -71,6 +71,7 @@ class SeriesList(SeriesMixin, ListAPIView):
     filter_class = SeriesFilter
     search_fields = ('name',)
     ordering_fields = ('id', 'name', 'date', 'submitter', 'received_all')
+    ordering = 'id'
 
 
 class SeriesDetail(SeriesMixin, RetrieveAPIView):
diff --git a/patchwork/api/user.py b/patchwork/api/user.py
index 32fe836ac826..1bfad43d6a9c 100644
--- a/patchwork/api/user.py
+++ b/patchwork/api/user.py
@@ -58,6 +58,7 @@ class UserList(UserMixin, ListAPIView):
 
     search_fields = ('username', 'first_name', 'last_name', 'email')
     ordering_fields = ('id', 'username', 'email')
+    ordering = 'id'
 
 
 class UserDetail(UserMixin, RetrieveUpdateAPIView):
-- 
2.11.0



More information about the Patchwork mailing list