From 756867da194c26626dad472830db366d7a18d2be Mon Sep 17 00:00:00 2001 From: Lebaud Antoine Date: Fri, 8 Mar 2024 18:41:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5(pagination)=20remove=20unused=20or?= =?UTF-8?q?dering=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our Pagination class inherits from the PageNumberPagination Django class. However, this base class as not ordering attribute. Thus, setting a default value wont have any effect on the code. Why did we end up passing a value to this non-existing attribute? Becasue we copy/pasted some code sources from Joanie, and Joanie also has this attribute set to a default value. If you take a look at DRF pagination style documentation, the only three attributes they set on the child class are 'page_size', 'max_page_size' 'page_size_query_param'. 'ordering' is not mentionned in the attributes you may override. However, the CursorPagination class offers the latter attribute, which may explain why we did end up setting this non-existing attribute in Joanie. --- src/backend/core/api/viewsets.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index 1dcfa84..92bbdc7 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -97,7 +97,6 @@ class SerializerPerActionMixin: class Pagination(pagination.PageNumberPagination): """Pagination to display no more than 100 objects per page sorted by creation date.""" - ordering = "-created_on" max_page_size = 100 page_size_query_param = "page_size"