: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(signals): treat invalid saved queries as a known anomaly scoring failure (#122441)
posthog[bot]073e8356027b
diff --git a/products/signals/backend/anomaly_scores/tick.py b/products/signals/backend/anomaly_scores/tick.pyindex 9a51f3616e22..312f9706c904 100644--- a/products/signals/backend/anomaly_scores/tick.py+++ b/products/signals/backend/anomaly_scores/tick.py@@ -16,7 +16,7 @@ import structlogfrom temporalio import activity, workflowfrom temporalio.common import RetryPolicy-from posthog.hogql.errors import TableAccessDeniedError+from posthog.hogql.errors import QueryError, TableAccessDeniedErrorfrom posthog.dataclasses import frozenfrom posthog.exceptions import (@@ -69,6 +69,8 @@ STATUS_MISSING = "missing"STATUS_TOO_EXPENSIVE = "too_expensive"# The insight's creator cannot read a table of the query.STATUS_ACCESS_DENIED = "access_denied"+# The saved query is invalid, for example it reads a warehouse table that no longer exists.+STATUS_BROKEN_QUERY = "broken_query"# Any other failure. The activity raises it, and the workflow counts it as `errored`.STATUS_ERRORED = "errored"@@ -154,8 +156,12 @@ def failure_status(error: Exception) -> str | None:ClickHouseQueryTimeOut | ClickHouseQueryMemoryLimitExceeded | ClickHouseEstimatedQueryExecutionTimeTooLong,):return STATUS_TOO_EXPENSIVE+ # A subclass of QueryError, so check it first.if isinstance(error, TableAccessDeniedError):return STATUS_ACCESS_DENIED+ # Only the exposed invalid-query error, such as an unknown table. ResolutionError is internal to the engine.+ if isinstance(error, QueryError):+ return STATUS_BROKEN_QUERYreturn Nonediff --git a/products/signals/backend/test/test_anomaly_scoring_tick.py b/products/signals/backend/test/test_anomaly_scoring_tick.pyindex 61773af34882..22317a029d3e 100644--- a/products/signals/backend/test/test_anomaly_scoring_tick.py+++ b/products/signals/backend/test/test_anomaly_scoring_tick.py@@ -13,7 +13,7 @@ from parameterized import parameterizedfrom posthog.schema import IntervalType-from posthog.hogql.errors import TableAccessDeniedError+from posthog.hogql.errors import QueryError, ResolutionError, TableAccessDeniedErrorfrom posthog.exceptions import ClickHouseClusterMemoryLimitExceeded, ClickHouseQueryTimeOutfrom posthog.models import Organization, Team, User@@ -261,6 +261,7 @@ class TestRunInsight(SimpleTestCase):[("timeout", ClickHouseQueryTimeOut(), "too_expensive"),("access_denied", TableAccessDeniedError("no access"), "access_denied"),+ ("unknown_table", QueryError("Unknown table `deleted_table`."), "broken_query"),("unsupported", UnsupportedInsightError("not trends"), "unsupported"),])@@ -278,6 +279,7 @@ class TestRunInsight(SimpleTestCase):@parameterized.expand([("cluster_memory", ClickHouseClusterMemoryLimitExceeded()),+ ("internal_resolver", ResolutionError("Type already resolved for Field (FieldType). Can't run again.")),("unknown", RuntimeError("boom")),])