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(hogql): deflake union by name row order (#74013)

Raúl Negrón-Oterod691d504ddae
diff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.py
index eb2053f4b2c6..6c581b225bc5 100644
--- a/posthog/hogql/printer/test/test_printer.py
+++ b/posthog/hogql/printer/test/test_printer.py
@@ -470,7 +470,9 @@ class TestPrinter(BaseTest):
def test_union_by_name_executes_on_clickhouse(self):
sql = self._select("select 1 as a, 2 as b union all by name select 3 as b, 4 as a")
- self.assertEqual(sync_execute(sql), [(1, 2), (4, 3)])
+ # UNION ALL branches come back in whatever order they finish, so sort before comparing:
+ # what matters here is that BY NAME lowering paired each value with the right column.
+ self.assertEqual(sorted(sync_execute(sql)), [(1, 2), (4, 3)])
def test_union_by_name_nested_set_operand_reorders_every_leaf(self):
response = self._select(