[PATCH 15/19] REST: Specify default ordering fields

Stephen Finucane stephen at that.guru
Thu May 11 05:45:24 AEST 2017


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>
---
 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 88d74a5..cd3e0c3 100644
--- a/patchwork/api/bundle.py
+++ b/patchwork/api/bundle.py
@@ -73,6 +73,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 d368265..d4aa223 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -99,6 +99,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 8b8d47b..55393f2 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -70,6 +70,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 a060022..b299227 100644
--- a/patchwork/api/event.py
+++ b/patchwork/api/event.py
@@ -97,13 +97,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 1e5c13f..32422cb 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -145,6 +145,7 @@ class PatchList(ListAPIView):
     search_fields = ('name',)
     ordering_fields = ('id', 'name', 'project', 'date', 'state', 'archived',
                        'submitter', 'check')
+    ordering = 'id'
 
     def get_queryset(self):
         return Patch.objects.all().with_tag_counts()\
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index 7947f82..20b4ad6 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -48,6 +48,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 ce3ed58..c334998 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -77,6 +77,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 3d5847b..5e6ab07 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -60,6 +60,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 32fe836..1bfad43 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.9.3



More information about the Patchwork mailing list