: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(pulse): break created_at ties in the brief list order (#102633)
posthog[bot]67c95b6a4be1
diff --git a/products/pulse/backend/api/brief.py b/products/pulse/backend/api/brief.pyindex bb0bc7fb35e2..12992010b13b 100644--- a/products/pulse/backend/api/brief.py+++ b/products/pulse/backend/api/brief.py@@ -277,7 +277,7 @@ class BriefConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):BriefConfig.objects.for_team(self.team_id).filter(created_by=cast(User, self.request.user)).select_related("created_by")- .order_by("-created_at")+ .order_by("-created_at", "-id"))# Lists hide soft-deleted configs; detail routes keep them reachable so a# PATCH {"deleted": false} can restore one.@@ -328,7 +328,7 @@ class ProductBriefViewSet(TeamAndOrgViewSetMixin, viewsets.ReadOnlyModelViewSet)ProductBrief.objects.for_team(self.team_id).filter(created_by=cast(User, self.request.user)).select_related("created_by", "config")- .order_by("-created_at")+ .order_by("-created_at", "-id"))def get_throttles(self) -> list[BaseThrottle]:diff --git a/products/pulse/backend/test/test_api.py b/products/pulse/backend/test/test_api.pyindex 430da7e64ce7..a72c220e1b92 100644--- a/products/pulse/backend/test/test_api.py+++ b/products/pulse/backend/test/test_api.py@@ -4,7 +4,9 @@ from posthog.test.base import APIBaseTestfrom unittest.mock import AsyncMock, MagicMock, patchfrom django.conf import settings+from django.utils import timezone+from parameterized import parameterizedfrom rest_framework import statusfrom temporalio.exceptions import WorkflowAlreadyStartedError@@ -335,6 +337,36 @@ class TestPulseAPI(APIBaseTest):)assert bad.status_code == status.HTTP_400_BAD_REQUEST+ @parameterized.expand(+ [+ ("brief_configs", BriefConfig, {"name": "tie"}),+ ("briefs", ProductBrief, {"trigger": ProductBrief.Trigger.ON_DEMAND}),+ ]+ )+ def test_list_pages_do_not_repeat_or_skip_rows_on_a_created_at_tie(+ self,+ _mock_connect: MagicMock,+ _mock_flag: MagicMock,+ route: str,+ model: type[BriefConfig] | type[ProductBrief],+ extra_fields: dict,+ ) -> None:+ # Ascending ids in insertion order, so the physical row order contradicts the newest-first+ # order the list owes. created_at is auto_now_add, so the tie is forced after the insert.+ row_ids = [uuid.UUID(f"018f0000-0000-7000-8000-00000000000{n}") for n in range(1, 5)]+ with team_scope(self.team.pk, canonical=True):+ for row_id in row_ids:+ model.objects.create(id=row_id, team=self.team, created_by=self.user, **extra_fields)+ model.objects.filter(pk__in=row_ids).update(created_at=timezone.now())++ paged: list[str] = []+ for offset in (0, 2):+ response = self.client.get(f"/api/projects/{self.team.id}/pulse/{route}/?limit=2&offset={offset}")+ assert response.status_code == status.HTTP_200_OK+ paged += [row["id"] for row in response.json()["results"]]++ assert paged == [str(row_id) for row_id in sorted(row_ids, reverse=True)]+def test_generate_rejects_last_n_days_without_days(self, mock_connect: MagicMock, _mock_flag: MagicMock) -> None:response = self.client.post(f"/api/projects/{self.team.id}/pulse/briefs/generate/",