: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): validate issueId in the similar issues runner (#106004)
posthog[bot]9b46d73fd962
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.pyindex cfda9995690b..2ebb1a0c87b0 100644--- a/posthog/hogql_queries/query_runner.py+++ b/posthog/hogql_queries/query_runner.py@@ -31,7 +31,10 @@ import structlogimport posthoganalyticsfrom prometheus_client import Counter, Histogramfrom pydantic import BaseModel, ConfigDict-from rest_framework.exceptions import ValidationError as DRFValidationError+from rest_framework.exceptions import (+ NotFound as DRFNotFound,+ ValidationError as DRFValidationError,+)from posthog.schema import (AccountsQuery,@@ -441,18 +444,19 @@ def _classify_error_for_slo(exc: Exception) -> tuple[QueryErrorCategory, SloOutc(EstimatedQueryExecutionTimeTooLong, QuerySizeExceeded) are a minorityworth living with for now.- UserAccessControlError and DRF ValidationError are folded into USER_ERROR- locally since classify_query_error doesn't recognise them, but a 403 or a- 400 is the user's input, not a service failure. A ValidationError with an- explicit cause is a technical error a runner converted for display (e.g.- the experiments error handler wrapping a ClickHouse OOM) — classify the- original so real platform failures keep failing the SLO.+ UserAccessControlError, DRF ValidationError and DRF NotFound are folded into+ USER_ERROR locally since classify_query_error doesn't recognise them, but a+ 403, a 400 or a 404 is the user's input, not a service failure. A+ ValidationError with an explicit cause is a technical error a runner+ converted for display (e.g. the experiments error handler wrapping a+ ClickHouse OOM) — classify the original so real platform failures keep+ failing the SLO."""if isinstance(exc, DRFValidationError):if isinstance(exc.__cause__, Exception):return _classify_error_for_slo(exc.__cause__)return QueryErrorCategory.USER_ERROR, SloOutcome.SUCCESS- if isinstance(exc, UserAccessControlError):+ if isinstance(exc, UserAccessControlError | DRFNotFound):return QueryErrorCategory.USER_ERROR, SloOutcome.SUCCESSif isinstance(exc, APIQueriesBudgetExceeded):# A team over its budget is refused on purpose, not a platform failure.diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.pyindex 7c6552990e07..df67cb53fb98 100644--- a/posthog/hogql_queries/test/test_query_runner.py+++ b/posthog/hogql_queries/test/test_query_runner.py@@ -19,7 +19,7 @@ from django.test.utils import CaptureQueriesContextfrom clickhouse_driver.errors import ServerExceptionfrom parameterized import parameterizedfrom pydantic import BaseModel-from rest_framework.exceptions import ValidationError+from rest_framework.exceptions import NotFound, ValidationErrorfrom posthog.schema import (ActorsQuery,@@ -1421,6 +1421,15 @@ class TestQueryRunner(BaseTest):"query_performance_error",True,),+ (+ # A runner that cannot find the row the user asked for — rendered as a 404,+ # so it must not fail the SLO or reach error tracking.+ "drf_not_found",+ lambda: NotFound("No matching fingerprints found"),+ SloOutcome.SUCCESS,+ "user_error",+ False,+ ),(# A follower whose leader left nothing to serve fails the SLO; the leader's capture and# the flight metrics already account for it.diff --git a/products/error_tracking/backend/hogql_queries/error_tracking_similar_issues_query_runner.py b/products/error_tracking/backend/hogql_queries/error_tracking_similar_issues_query_runner.pyindex 2502dcad97e2..c877926faff7 100644--- a/products/error_tracking/backend/hogql_queries/error_tracking_similar_issues_query_runner.py+++ b/products/error_tracking/backend/hogql_queries/error_tracking_similar_issues_query_runner.py@@ -27,6 +27,7 @@ from posthog.hogql_queries.paginators import HogQLHasMorePaginatorfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom products.error_tracking.backend.hogql_queries.access import ErrorTrackingQueryRunnerAccessMixin+from products.error_tracking.backend.hogql_queries.error_tracking_query_runner_utils import validate_uuid_paramfrom products.error_tracking.backend.models import ErrorTrackingIssueFingerprintV2logger = structlog.get_logger(__name__)@@ -98,7 +99,7 @@ class ErrorTrackingSimilarIssuesQueryRunner(limit=self.query.limit if self.query.limit else None,offset=self.query.offset,)- ## Validate query+ self.query.issueId = validate_uuid_param(self.query.issueId, "issueId")def _calculate(self):res: tuple[list[SimilarFingerprint], HogQLQueryResponse] = self.get_similar_fingerprints()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 abf32f59553f..2f5bb70044b1 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@@ -1432,6 +1432,16 @@ class TestErrorTrackingQueryRunner(ClickhouseTestMixin, NonAtomicBaseTestKeepIde)self.assertEqual(runner.query.issueId, "01936e7f-d7ff-7314-b2d4-7627981e34f0")+ def test_similar_issues_rejects_malformed_issue_id(self):+ with self.assertRaises(ValidationError):+ ErrorTrackingSimilarIssuesQueryRunner(+ team=self.team,+ query=ErrorTrackingSimilarIssuesQuery(+ kind="ErrorTrackingSimilarIssuesQuery",+ issueId="not-a-uuid",+ ),+ )+def test_similar_issues_ignores_another_teams_fingerprint_row(self):ErrorTrackingIssue.objects.filter(id=self.issue_id_one).update(description="Own team issue")other_team = Team.objects.create(organization=self.organization, name="Other team")