: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(error-tracking): make every issue list sort a total order (#116993)
James Gill628331251861
diff --git a/products/error_tracking/backend/hogql_queries/error_tracking_query_runner_utils.py b/products/error_tracking/backend/hogql_queries/error_tracking_query_runner_utils.pyindex 9ec9f9990a88..98e01a5059e6 100644--- a/products/error_tracking/backend/hogql_queries/error_tracking_query_runner_utils.py+++ b/products/error_tracking/backend/hogql_queries/error_tracking_query_runner_utils.py@@ -174,27 +174,27 @@ SEVERITY_RANKING: list[str] = [def order_by_exprs(query: ErrorTrackingQuery) -> list[ast.OrderExpr]:direction = order_direction(query)- if query.orderBy != ErrorTrackingOrderBy.SEVERITY:- return [ast.OrderExpr(expr=ast.Field(chain=[query.orderBy]), order=direction)]-- # Sorting on the `severity` column itself is wrong two ways, and both fail silently. It is a- # Nullable(String), so the order is alphabetical (critical, high, low, medium), and ClickHouse- # ranks NULL above every value, so DESC leads with the unset majority. Sort on the position in- # SEVERITY_RANKING instead. `indexOf` gives 1 to 4 for a known level and 0 for a value that is- # not in the array, and a NULL needle also gives 0, so unset ranks below `low`.- severity_rank = ast.Call(- name="indexOf",- args=[- ast.Array(exprs=[ast.Constant(value=level) for level in SEVERITY_RANKING]),- ast.Field(chain=["severity"]),- ],- )- # Four levels plus unset leave most rows sharing a rank. The paginator pages with LIMIT/OFFSET- # over a re-run query, so rows move between pages and the infinite scroll repeats and drops- # them unless the order is total. `last_seen` puts the most recently seen issue first within a- # rank, and `id` is the GROUP BY key of both query shapes, so adding it makes the order total.- return [- ast.OrderExpr(expr=severity_rank, order=direction),- ast.OrderExpr(expr=ast.Field(chain=["last_seen"]), order="DESC"),- ast.OrderExpr(expr=ast.Field(chain=["id"]), order="DESC"),+ primary: ast.Expr = ast.Field(chain=[query.orderBy])+ if query.orderBy == ErrorTrackingOrderBy.SEVERITY:+ # Sorting on the `severity` column itself is wrong two ways, and both fail silently. It is a+ # Nullable(String), so the order is alphabetical (critical, high, low, medium), and ClickHouse+ # ranks NULL above every value, so DESC leads with the unset majority. Sort on the position in+ # SEVERITY_RANKING instead. `indexOf` gives 1 to 4 for a known level and 0 for a value that is+ # not in the array, and a NULL needle also gives 0, so unset ranks below `low`.+ primary = ast.Call(+ name="indexOf",+ args=[+ ast.Array(exprs=[ast.Constant(value=level) for level in SEVERITY_RANKING]),+ ast.Field(chain=["severity"]),+ ],+ )++ # The paginator pages with LIMIT/OFFSET over a re-run query, and ClickHouse returns tied rows in+ # any order, so tied rows move between pages and the infinite scroll repeats and drops them+ # unless the order is total. Small counts such as occurrences and users tie often, and so do the+ # few severity ranks. `last_seen` puts the most recently seen issue first within a tie, and `id`+ # is the GROUP BY key of both query shapes, so adding it makes the order total.+ tiebreakers = [+ ast.OrderExpr(expr=ast.Field(chain=[key]), order="DESC") for key in ("last_seen", "id") if key != query.orderBy]+ return [ast.OrderExpr(expr=primary, order=direction), *tiebreakers]diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambrindex e0b2784f2403..793462904078 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr@@ -48,7 +48,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -113,7 +114,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -168,7 +170,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -215,7 +218,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2016-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(greaterOrEquals(e__fingerprint_issue_state.first_seen, parseDateTime64BestEffort('2020-01-10T10:11:00+00:00', 6, 'UTC')), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -262,7 +266,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2016-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(less(e__fingerprint_issue_state.first_seen, parseDateTime64BestEffort('2020-01-10T10:11:00+00:00', 6, 'UTC')), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -317,7 +322,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -372,7 +378,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -427,7 +434,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -482,7 +490,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -537,7 +546,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -584,7 +594,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2018-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(equals(e__fingerprint_issue_state.issue_name, 'TypeError'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -649,7 +660,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -704,7 +716,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -759,7 +772,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -814,7 +828,9 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY first_seen ASC+ ORDER BY first_seen ASC,+ last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -879,7 +895,9 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY occurrences DESC+ ORDER BY occurrences DESC,+ last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -941,7 +959,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -996,7 +1015,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1061,7 +1081,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1126,7 +1147,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1191,7 +1213,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, 'e9ac529f-ac1c-4a96-bd3a-102334368d64'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1256,7 +1279,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambrindex fbfc426ef0ca..f17a7de88f81 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr@@ -48,7 +48,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -115,7 +116,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -172,7 +174,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -221,7 +224,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(nullIf(toString(e.properties.`$exception_fingerprint`), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_fingerprint`), '[]'), '{}'), toString(e.properties.`$exception_fingerprint`))))), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2016-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(less(e__fingerprint_issue_state.first_seen, parseDateTime64BestEffort('2020-01-10T10:11:00+00:00', 6, 'UTC')), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -270,7 +274,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(nullIf(toString(e.properties.`$exception_fingerprint`), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_fingerprint`), '[]'), '{}'), toString(e.properties.`$exception_fingerprint`))))), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2016-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(greaterOrEquals(e__fingerprint_issue_state.first_seen, parseDateTime64BestEffort('2020-01-10T10:11:00+00:00', 6, 'UTC')), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -327,7 +332,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -384,7 +390,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -441,7 +448,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -498,7 +506,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -555,7 +564,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -604,7 +614,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__fingerprint_issue_state ON equals(cityHash64(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(nullIf(toString(e.properties.`$exception_fingerprint`), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_fingerprint`), '[]'), '{}'), toString(e.properties.`$exception_fingerprint`))))), e__fingerprint_issue_state.fp_hash)WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(e__fingerprint_issue_state.issue_id), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('2018-01-11 12:11:00.000000', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), ifNull(equals(e__fingerprint_issue_state.issue_name, 'TypeError'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -671,7 +682,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, '01936e7f-d7ff-7314-b2d4-7627981e34f0'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -728,7 +740,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -785,7 +798,9 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY first_seen ASC+ ORDER BY first_seen ASC,+ last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -842,7 +857,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -909,7 +925,9 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY occurrences DESC+ ORDER BY occurrences DESC,+ last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -973,7 +991,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1030,7 +1049,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1097,7 +1117,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1164,7 +1185,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1231,7 +1253,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE and(isNotNull(fp_state.issue_id), ifNull(equals(fp_state.issue_id, 'e9ac529f-ac1c-4a96-bd3a-102334368d64'), 0))GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,@@ -1298,7 +1321,8 @@HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)WHERE isNotNull(fp_state.issue_id)GROUP BY id- ORDER BY last_seen DESC+ ORDER BY last_seen DESC,+ id DESCLIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,diff --git a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.pyindex 3d8c6806cf19..03594ebaa303 100644--- a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py+++ b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py@@ -772,41 +772,40 @@ class TestErrorTrackingQueryRunner(ClickhouseTestMixin, NonAtomicBaseTestKeepIde@parameterized.expand([- ("optimized_shape_descending", False, "DESC"),- ("optimized_shape_ascending", False, "ASC"),- ("legacy_shape_descending", True, "DESC"),- ("legacy_shape_ascending", True, "ASC"),+ ("severity", ["indexOf(['low', 'medium', 'high', 'critical'], severity)", "last_seen", "id"]),+ ("occurrences", ["occurrences", "last_seen", "id"]),+ ("users", ["users", "last_seen", "id"]),+ ("sessions", ["sessions", "last_seen", "id"]),+ ("first_seen", ["first_seen", "last_seen", "id"]),+ ("last_seen", ["last_seen", "id"]),])@time_machine.travel("2022-01-10T12:11:00", tick=False)- def test_severity_ordering_is_total(self, _name: str, legacy_shape: bool, direction: str):- # Most rows share a severity, and the paginator pages with LIMIT/OFFSET, so rows repeat and- # drop between pages unless the tiebreakers make the order total in both directions.- filter_group = self._severity_is_set_filter() if legacy_shape else None-- builder = ErrorTrackingQueryBuilder(- query=ErrorTrackingQuery(- kind="ErrorTrackingQuery",- dateRange=DateRange(date_from="-7d"),- filterGroup=filter_group,- orderBy="severity",- orderDirection=direction, # pyright: ignore[reportArgumentType]- volumeResolution=1,- ),- team=self.team,- date_from=datetime(2022, 1, 3, tzinfo=UTC),- date_to=datetime(2022, 1, 10, tzinfo=UTC),- )- self.assertEqual(builder._needs_legacy_shape(), legacy_shape)-- self.assertEqual(- [(order.expr.to_hogql(), order.order) for order in builder.build_query().order_by or []],- [- ("indexOf(['low', 'medium', 'high', 'critical'], severity)", direction),- ("last_seen", "DESC"),- ("id", "DESC"),- ],- )+ def test_ordering_is_total(self, order_by: str, expected_keys: list[str]):+ # Rows share sort values, and the paginator pages with LIMIT/OFFSET, so rows repeat and drop+ # between pages unless the tiebreakers make the order total in both shapes and directions.+ primary, *tiebreakers = expected_keys+ for legacy_shape in (False, True):+ for direction in ("DESC", "ASC"):+ builder = ErrorTrackingQueryBuilder(+ query=ErrorTrackingQuery(+ kind="ErrorTrackingQuery",+ dateRange=DateRange(date_from="-7d"),+ filterGroup=self._severity_is_set_filter() if legacy_shape else None,+ orderBy=order_by, # pyright: ignore[reportArgumentType]+ orderDirection=direction, # pyright: ignore[reportArgumentType]+ volumeResolution=1,+ ),+ team=self.team,+ date_from=datetime(2022, 1, 3, tzinfo=UTC),+ date_to=datetime(2022, 1, 10, tzinfo=UTC),+ )+ self.assertEqual(builder._needs_legacy_shape(), legacy_shape)+ self.assertEqual(+ [(order.expr.to_hogql(), order.order) for order in builder.build_query().order_by or []],+ [(primary, direction), *((key, "DESC") for key in tiebreakers)],+ f"legacy_shape={legacy_shape} direction={direction}",+ )@time_machine.travel("2022-01-10T12:11:00", tick=False)def test_status(self):