: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(query): don't re-capture query-failure-cache replays (#74235)
posthog[bot]3e79895a8f33
diff --git a/posthog/api/query.py b/posthog/api/query.pyindex 6ac43470411c..1a49cb74721b 100644--- a/posthog/api/query.py+++ b/posthog/api/query.py@@ -347,7 +347,9 @@ class QueryViewSet(QueryCoalescingMixin, TeamAndOrgViewSetMixin, PydanticModelMiexcept ConcurrencyLimitExceeded as c:self._raise_concurrency_throttled(c)except Exception as e:- capture_exception(e)+ # Breaker replays were already captured when the original failure happened.+ if not getattr(e, "served_from_query_failure_cache", False):+ capture_exception(e)raise@extend_schema(@@ -449,7 +451,9 @@ class QueryViewSet(QueryCoalescingMixin, TeamAndOrgViewSetMixin, PydanticModelMiexcept ConcurrencyLimitExceeded as c:self._raise_concurrency_throttled(c)except Exception as e:- capture_exception(e)+ # Breaker replays were already captured when the original failure happened.+ if not getattr(e, "served_from_query_failure_cache", False):+ capture_exception(e)raisedef handle_column_ch_error(self, error):diff --git a/posthog/api/test/test_query.py b/posthog/api/test/test_query.pyindex ca71b54d5f13..9ddf7c436d7a 100644--- a/posthog/api/test/test_query.py+++ b/posthog/api/test/test_query.py@@ -42,6 +42,7 @@ from posthog.clickhouse.client import sync_executefrom posthog.clickhouse.client.limit import ConcurrencyLimitExceededfrom posthog.clickhouse.query_tagging import Product, QueryTagsfrom posthog.event_usage import EventSource+from posthog.exceptions import ClickHouseQueryTimeOutfrom posthog.models.utils import UUIDTfrom products.event_definitions.backend.models.property_definition import PropertyDefinition, PropertyType@@ -65,6 +66,27 @@ class TestQuery(ClickhouseTestMixin, APIBaseTest):self.assertEqual(detail, CONCURRENCY_LIMIT_USER_MESSAGE)self.assertNotIn("app:query:per-org", detail)+ @parameterized.expand(+ [+ ("served_from_cache", True, False),+ ("fresh_failure", False, True),+ ]+ )+ def test_served_from_query_failure_cache_is_not_recaptured(self, _name, served_from_cache, expect_capture):+ error = ClickHouseQueryTimeOut("failed the same way 3 times in a row")+ if served_from_cache:+ error.served_from_query_failure_cache = True # type: ignore[attr-defined]+ with (+ patch("posthog.api.query.process_query_model", side_effect=error),+ patch("posthog.api.query.capture_exception") as mock_capture,+ ):+ response = self.client.post(+ f"/api/environments/{self.team.id}/query/",+ {"query": HogQLQuery(query="select 1").model_dump()},+ )+ self.assertEqual(response.status_code, ClickHouseQueryTimeOut.status_code)+ self.assertEqual(mock_capture.called, expect_capture)+@snapshot_clickhouse_queriesdef test_select_hogql_expressions(self):with freeze_time("2020-01-10 12:00:00"):