:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(quick-filters): give the list a stable pagination order (#101899)
posthog[bot]42fe4c5cdeb8
diff --git a/posthog/api/quick_filters.py b/posthog/api/quick_filters.pyindex 21dc5acf6b88..b21b59662c9a 100644--- a/posthog/api/quick_filters.py+++ b/posthog/api/quick_filters.py@@ -167,7 +167,8 @@ class QuickFilterViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):context = self.request.query_params.get("context")if context:queryset = queryset.filter(context_memberships__context=context).distinct()- return queryset.order_by("-created_at")+ # created_at is not unique, so it cannot page reliably on its own+ return queryset.order_by("-created_at", "-id")def perform_destroy(self, instance):with transaction.atomic():diff --git a/posthog/api/test/test_quick_filters.py b/posthog/api/test/test_quick_filters.pyindex a0969ca32249..87ed353e1e74 100644--- a/posthog/api/test/test_quick_filters.py+++ b/posthog/api/test/test_quick_filters.py@@ -51,6 +51,24 @@ class TestQuickFilters(APIBaseTest):self.assertEqual(response.status_code, status.HTTP_200_OK)self.assertEqual(len(response.json()["results"]), 2)+ def test_list_quick_filters_pages_do_not_overlap_when_created_at_ties(self):+ for index in range(5):+ self._create_quick_filter(f"Filter {index}", f"$prop{index}")+ QuickFilter.objects.filter(team=self.team).update(created_at="2026-01-01T00:00:00Z")+ expected_order = [+ str(filter_id)+ for filter_id in QuickFilter.objects.filter(team=self.team).order_by("-id").values_list("id", flat=True)+ ]++ first_page = self.client.get(f"/api/environments/{self.team.id}/quick_filters/?limit=3")+ second_page = self.client.get(f"/api/environments/{self.team.id}/quick_filters/?limit=3&offset=3")++ self.assertEqual(first_page.status_code, status.HTTP_200_OK)+ self.assertEqual(second_page.status_code, status.HTTP_200_OK)+ paged_ids = [row["id"] for row in first_page.json()["results"]]+ paged_ids += [row["id"] for row in second_page.json()["results"]]+ self.assertEqual(paged_ids, expected_order)+def test_list_quick_filters_by_context(self):self._create_quick_filter("Dashboard Filter", "$dashboard_prop")self._create_quick_filter("Logs Filter", "$logs_prop", contexts=["logs-filters"])