From 9e0adc77dd50633d2c5b5cefc0c757a7472124c7 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Tue, 29 Nov 2022 17:40:09 +0200 Subject: [PATCH] Make sure `id` field is included in ordering --- apiserver/database/model/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apiserver/database/model/base.py b/apiserver/database/model/base.py index ef654c4..6b8524b 100644 --- a/apiserver/database/model/base.py +++ b/apiserver/database/model/base.py @@ -522,6 +522,8 @@ class GetMixin(PropsMixin): def validate_order_by(cls, parameters, search_text) -> Sequence: """ Validate and extract order_by params as a list + If ordering is specified then make sure that id field is part of it + This guarantees the unique order when paging """ order_by = parameters.get(cls._ordering_key) if not order_by: @@ -534,6 +536,9 @@ class GetMixin(PropsMixin): "text score cannot be used in order_by when search text is not used" ) + if not any(id_field in order_by for id_field in ("id", "-id")): + order_by.append("id") + return order_by @classmethod