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.

chore(groups): make order-sensitive groups query-runner tests deterministic (#64446)

posthog[bot]b3642c8c2ffe
diff --git a/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr b/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr
index 50bfc48be49d..a6146f27499d 100644
--- a/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr
+++ b/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr
@@ -4,7 +4,6 @@
SELECT tuple(coalesce(toString(groups.properties___name), toString(groups.key)), toString(groups.key)) AS `tuple(coalesce(toString(properties.name), toString(key)), toString(key))`
FROM
(SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,
- tupleElement(argMax(tuple(toTimeZone(groups.created_at, 'UTC')), toTimeZone(groups._timestamp, 'UTC')), 1) AS created_at,
groups.group_type_index AS index,
groups.group_key AS key
FROM groups
@@ -12,7 +11,7 @@
GROUP BY groups.group_type_index,
groups.group_key) AS groups
WHERE equals(groups.index, 0)
- ORDER BY groups.created_at DESC
+ ORDER BY groups.key ASC
LIMIT 11
OFFSET 0 SETTINGS readonly=2,
max_execution_time=60,
@@ -124,7 +123,6 @@
SELECT tuple(coalesce(toString(groups.properties___name), toString(groups.key)), toString(groups.key)) AS `tuple(coalesce(toString(properties.name), toString(key)), toString(key))`
FROM
(SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,
- tupleElement(argMax(tuple(toTimeZone(groups.created_at, 'UTC')), toTimeZone(groups._timestamp, 'UTC')), 1) AS created_at,
groups.group_type_index AS index,
groups.group_key AS key
FROM groups
@@ -132,7 +130,7 @@
GROUP BY groups.group_type_index,
groups.group_key) AS groups
WHERE equals(groups.index, 0)
- ORDER BY groups.created_at DESC
+ ORDER BY groups.key ASC
LIMIT 11
OFFSET 2 SETTINGS readonly=2,
max_execution_time=60,
@@ -246,7 +244,6 @@
FROM
(SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,
tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'arr'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___arr,
- tupleElement(argMax(tuple(toTimeZone(groups.created_at, 'UTC')), toTimeZone(groups._timestamp, 'UTC')), 1) AS created_at,
groups.group_type_index AS index,
groups.group_key AS key
FROM groups
@@ -254,7 +251,7 @@
GROUP BY groups.group_type_index,
groups.group_key) AS groups
WHERE equals(groups.index, 0)
- ORDER BY groups.created_at DESC
+ ORDER BY groups.key ASC
LIMIT 11
OFFSET 0 SETTINGS readonly=2,
max_execution_time=60,
diff --git a/posthog/hogql_queries/groups/test/test_groups_query_runner.py b/posthog/hogql_queries/groups/test/test_groups_query_runner.py
index 77b105027dc2..9515192b13eb 100644
--- a/posthog/hogql_queries/groups/test/test_groups_query_runner.py
+++ b/posthog/hogql_queries/groups/test/test_groups_query_runner.py
@@ -63,6 +63,7 @@ class TestGroupsQueryRunner(ClickhouseTestMixin, APIBaseTest):
group_type_index=0,
limit=10,
offset=0,
+ orderBy=["key"],
)
query_runner = GroupsQueryRunner(query=query, team=self.team)
result = query_runner.calculate()
@@ -96,7 +97,7 @@ class TestGroupsQueryRunner(ClickhouseTestMixin, APIBaseTest):
properties={"name": i * 10},
)
- query = GroupsQuery(group_type_index=0, limit=10, offset=0)
+ query = GroupsQuery(group_type_index=0, limit=10, offset=0, orderBy=["key"])
query_runner = GroupsQueryRunner(query=query, team=self.team)
result = query_runner.calculate()
@@ -114,6 +115,7 @@ class TestGroupsQueryRunner(ClickhouseTestMixin, APIBaseTest):
group_type_index=0,
limit=10,
offset=2,
+ orderBy=["key"],
)
query_runner = GroupsQueryRunner(query=query, team=self.team)
@@ -132,6 +134,7 @@ class TestGroupsQueryRunner(ClickhouseTestMixin, APIBaseTest):
limit=10,
offset=0,
select=["group_name", "key", "properties.arr"],
+ orderBy=["key"],
)
query_runner = GroupsQueryRunner(query=query, team=self.team)