Skip to content

: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.

fix(endpoints): list endpoints in a fixed order so offset pages hold (#130256)

Rafael Audibertd6ec8ed1b6b7
diff --git a/products/endpoints/backend/presentation/views/api.py b/products/endpoints/backend/presentation/views/api.py
index f00dcab05194..75a11fb9317b 100644
--- a/products/endpoints/backend/presentation/views/api.py
+++ b/products/endpoints/backend/presentation/views/api.py
@@ -211,7 +211,12 @@ class EndpointViewSet(
filterset_fields = ["is_active", "created_by"]
def safely_get_queryset(self, queryset):
- return queryset.filter(deleted=False)
+ queryset = queryset.filter(deleted=False)
+ if self.action == "list":
+ # Offset pages need a fixed order, or rows can repeat or go missing between pages. The
+ # partial index on (team, name) for undeleted endpoints serves this order.
+ queryset = queryset.order_by("name", "id")
+ return queryset
def get_serializer_class(self):
return serializers.Serializer # We use Pydantic models instead; this fallback satisfies drf-spectacular
diff --git a/products/endpoints/backend/tests/test_endpoint.py b/products/endpoints/backend/tests/test_endpoint.py
index f27819e12937..72d70e40b3e7 100644
--- a/products/endpoints/backend/tests/test_endpoint.py
+++ b/products/endpoints/backend/tests/test_endpoint.py
@@ -742,27 +742,24 @@ class TestEndpoint(ClickhouseTestMixin, APIBaseTest):
def test_list_no_filters(self):
"""Test listing all endpoints without filters."""
create_endpoint_with_version(
- name="query1",
+ name="query2",
team=self.team,
query=self.sample_hogql_query,
created_by=self.user,
- is_active=True,
+ is_active=False,
)
create_endpoint_with_version(
- name="query2",
+ name="query1",
team=self.team,
query=self.sample_hogql_query,
created_by=self.user,
- is_active=False,
+ is_active=True,
)
- # Test without any filters - should return all queries
response = self.client.get(f"/api/environments/{self.team.id}/endpoints/")
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
- response_data = response.json()
- self.assertEqual(len(response_data["results"]), 2)
- query_names = {q["name"] for q in response_data["results"]}
- self.assertEqual(query_names, {"query1", "query2"})
+ self.assertEqual([q["name"] for q in response.json()["results"]], ["query1", "query2"])
def test_create_endpoint_with_comprehensive_trends_query(self):
"""Test creating a endpoint with a comprehensive TrendsQuery containing many fields."""