: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(dashboards): page the dashboard list on a stable order (#103285)
posthog[bot]52245f81baed
diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambrindex b374c2aab15a..4b71335bb5bb 100644--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr@@ -4034,7 +4034,7 @@AND NOT ("posthog_dashboard"."creation_mode" = 'unlisted'))ORDER BY "posthog_dashboard"."pinned" DESC,"posthog_dashboard"."name" ASC,- "posthog_dashboard"."id" DESC+ "posthog_dashboard"."id" ASCLIMIT 300'''# ---@@ -16350,7 +16350,7 @@AND NOT ("posthog_dashboard"."creation_mode" = 'unlisted'))ORDER BY "posthog_dashboard"."pinned" DESC,"posthog_dashboard"."name" ASC,- "posthog_dashboard"."id" DESC+ "posthog_dashboard"."id" ASCLIMIT 100'''# ---diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.pyindex 5b7146d2e265..d8b1f7f69206 100644--- a/posthog/api/test/dashboards/test_dashboard.py+++ b/posthog/api/test/dashboards/test_dashboard.py@@ -483,6 +483,26 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):unseen_id,]+ @parameterized.expand(+ [+ ("default order", {}),+ ("pinned only", {"pinned": "true"}),+ ("search", {"search": "Tied"}),+ ]+ )+ def test_list_dashboards_pages_tied_rows_without_gaps_or_repeats(self, _name: str, query_params: dict) -> None:+ tied_ids = [self.dashboard_api.create_dashboard({"name": "Tied", "pinned": True})[0] for _ in range(5)]++ paged_ids: list[int] = []+ for offset in range(0, len(tied_ids), 2):+ response = self.dashboard_api.list_dashboards(+ parent="environment",+ query_params={**query_params, "limit": 2, "offset": offset},+ )+ paged_ids.extend(dashboard["id"] for dashboard in response["results"])++ assert paged_ids == sorted(tied_ids)+def test_list_includes_folder_from_filesystem(self):filed_id, _ = self.dashboard_api.create_dashboard({"name": "Filed dashboard", "_create_in_folder": "Marketing/Website"}diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.pyindex 42a3bba623f8..05236458578c 100644--- a/products/dashboards/backend/api/dashboard.py+++ b/products/dashboards/backend/api/dashboard.py@@ -2562,7 +2562,7 @@ class DashboardsViewSet(scope_object = "dashboard"# Record a tags change per dashboard when bulk_update_tags mutates it, matching the single-object path.bulk_tag_activity_scope = "Dashboard"- queryset = Dashboard.objects_including_soft_deleted.order_by("-pinned", "name")+ queryset = Dashboard.objects_including_soft_deleted.order_by("-pinned", "name", "id")permission_classes = [CanEditDashboard]renderer_classes = [SafeJSONRenderer, ServerSentEventRenderer]@@ -2648,7 +2648,7 @@ class DashboardsViewSet(span_prefix="dashboard.search",fields=(NAME_FIELD, DESCRIPTION_FIELD),include_tag_search=True,- tiebreakers=("-pinned", "name"),+ tiebreakers=("-pinned", "name", "id"),)@tracer.start_as_current_span("DashboardViewSet.dangerously_get_queryset")@@ -2746,7 +2746,7 @@ class DashboardsViewSet(queryset = queryset.exclude(name__startswith=GENERATED_DASHBOARD_PREFIX)if self.action == "list" and self.request.query_params.get("pinned") == "true":- queryset = queryset.filter(pinned=True).order_by(F("last_viewed_at").desc(nulls_last=True), "name")+ queryset = queryset.filter(pinned=True).order_by(F("last_viewed_at").desc(nulls_last=True), "name", "id")# Allow filtering by creation_mode query paramcreation_mode = self.request.query_params.get("creation_mode")