: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): match pasted issue ids in quick search (#107617)
Aleksander Błaszkiewicz738b57706085
diff --git a/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py b/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.pyindex a86fae439f05..0a702aaacc36 100644--- a/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py+++ b/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py@@ -1,6 +1,7 @@import datetimefrom collections.abc import Callablefrom typing import Any, cast+from uuid import UUIDfrom django.core.exceptions import ValidationError@@ -287,16 +288,23 @@ class ErrorTrackingQueryBuilder:# Shape dispatch# ---------------------------------------------------------------------+ def _search_issue_id(self) -> str | None:+ if not self.query.searchQuery:+ return None+ try:+ return str(UUID(self.query.searchQuery.strip()))+ except ValueError:+ return None+def _needs_legacy_shape(self) -> bool:- """Return True if the user-supplied filterGroup contains issue-level- filters that cannot be cleanly routed to the outer query.-- The two-pass shape can only split filters cleanly when all- issue-level leaves are AND-combined with the rest of the tree. If an- `ErrorTrackingIssueFilter` appears anywhere in the tree we fall back- to the legacy shape rather than risk producing wrong results for- mixed-OR groups.+ """Use the single-query shape when search or filters need resolved issue state.++ The two-pass shape filters events before it joins issue state, so it+ cannot match a current issue ID alongside event text. It also cannot+ preserve mixed issue/event filter groups."""+ if self._search_issue_id():+ return Trueif not self.query.filterGroup or not self.query.filterGroup.values:return Falsereturn self._tree_contains_issue_filter(self.query.filterGroup.values[0])@@ -979,7 +987,20 @@ class ErrorTrackingQueryBuilder:)and_exprs.append(ast.Or(exprs=or_exprs))- return ast.And(exprs=and_exprs)+ text_search = ast.And(exprs=and_exprs)+ issue_id = self._search_issue_id()+ if issue_id:+ return ast.Or(+ exprs=[+ text_search,+ ast.CompareOperation(+ op=ast.CompareOperationOp.Eq,+ left=self._legacy_issue_state_expr("issue_id"),+ right=ast.Constant(value=issue_id),+ ),+ ]+ )+ return text_searchdef _extract_assignee(self, row: dict) -> dict | None:user_id = row.get("assignee_user_id")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 c53101303fea..18c894899630 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@@ -502,6 +502,27 @@ class TestErrorTrackingQueryRunner(ClickhouseTestMixin, NonAtomicBaseTestKeepIdeself.assertEqual(results[1]["aggregations"]["sessions"], 0)self.assertEqual(results[1]["aggregations"]["users"], 1)+ @time_machine.travel("2022-01-10T12:11:00", tick=False)+ def test_search_query_matches_current_issue_id_and_event_text(self) -> None:+ current_issue_id = str(uuid7())+ self.create_issue(current_issue_id, "new_issue_fingerprint")+ self.override_fingerprint(self.issue_three_fingerprint, current_issue_id)+ _create_event(+ distinct_id=self.distinct_id_one,+ event="$exception",+ team=self.team,+ properties={+ "$exception_issue_id": self.issue_id_two,+ "$exception_fingerprint": self.issue_two_fingerprint,+ "$exception_values": f"An error mentions {current_issue_id}",+ },+ )+ flush_persons_and_events()++ results = self._calculate(searchQuery=f" {current_issue_id.upper()} ", withAggregations=True)["results"]++ self.assertEqual({result["id"] for result in results}, {current_issue_id, self.issue_id_two})+@time_machine.travel("2022-01-10T12:11:00", tick=False)@snapshot_clickhouse_queriesdef test_empty_search_query(self):