Skip to content

: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.

fix(subscriptions): tell a query-less insight apart from a failed query (#104034)

Thomas Obermüller7f2e07acac0f
diff --git a/products/exports/backend/tasks/image_exporter.py b/products/exports/backend/tasks/image_exporter.py
index b9024829a4ed..74fa1ca8e369 100644
--- a/products/exports/backend/tasks/image_exporter.py
+++ b/products/exports/backend/tasks/image_exporter.py
@@ -591,10 +591,11 @@ def export_image(
analytics_props=export_analytics_props,
)
elif exported_asset.insight.query is None:
- # Nothing to warm: the insight stores only legacy filters, which the render
- # converts in the browser. Failing here would lose an export the browser can
- # still produce, so the render just starts without a warm cache. The dashboard
- # branch below skips such a tile for the same reason.
+ # Nothing to warm: the insight stores only legacy filters, and nothing converts
+ # those into a query, so the insight renders blank. Raising here would fail the
+ # whole export instead of producing it with one blank insight, so the render
+ # starts without a warm cache. The dashboard branch below skips such a tile for
+ # the same reason.
logger.info(
"export_image.skip_warming_insight_without_query",
insight_id=exported_asset.insight.id,
diff --git a/products/exports/backend/temporal/subscriptions/insight_snapshot.py b/products/exports/backend/temporal/subscriptions/insight_snapshot.py
index cf0e6b10ec4d..a39dfd079c94 100644
--- a/products/exports/backend/temporal/subscriptions/insight_snapshot.py
+++ b/products/exports/backend/temporal/subscriptions/insight_snapshot.py
@@ -29,7 +29,7 @@ from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.exports.backend.models.subscription import Subscription
from products.exports.backend.temporal.subscriptions.delivery_common import strip_null_bytes
-from products.exports.backend.temporal.subscriptions.types import safe_error_message
+from products.exports.backend.temporal.subscriptions.types import MISSING_QUERY_ERROR_TYPE, safe_error_message
from products.product_analytics.backend.facade.models import Insight
logger = structlog.get_logger(__name__)
@@ -263,7 +263,7 @@ def build_insight_delivery_snapshot(
base["query_results"] = None
base["cache_key"] = None
base["query_error"] = {
- "type": "missing_query",
+ "type": MISSING_QUERY_ERROR_TYPE,
"message": "Insight has no query",
"human_readable_error": "This insight has no query to run.",
}
diff --git a/products/exports/backend/temporal/subscriptions/snapshot_activities.py b/products/exports/backend/temporal/subscriptions/snapshot_activities.py
index 269acaa4766e..54b6708b12d8 100644
--- a/products/exports/backend/temporal/subscriptions/snapshot_activities.py
+++ b/products/exports/backend/temporal/subscriptions/snapshot_activities.py
@@ -16,7 +16,11 @@ from products.exports.backend.models.exported_asset import ExportedAsset
from products.exports.backend.models.subscription import Subscription, SubscriptionDelivery
from products.exports.backend.temporal.subscriptions.llm_change_summary import generate_change_summary
from products.exports.backend.temporal.subscriptions.results_summarizer import build_results_summary
-from products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs, SnapshotInsightsResult
+from products.exports.backend.temporal.subscriptions.types import (
+ MISSING_QUERY_ERROR_TYPE,
+ SnapshotInsightsInputs,
+ SnapshotInsightsResult,
+)
from products.posthog_ai.backend.models.assistant import CoreMemory
from products.product_analytics.backend.facade.models import Insight
@@ -127,7 +131,14 @@ def _build_states_from_content_snapshot(
)
fallback_reason: str | None = None
elif query_error:
- results_summary = "Query failed"
+ # An insight that stores no query has nothing to run, which is not a failure. The
+ # remaining legacy filters-only insights reach this branch on every delivery, so a
+ # "Query failed" line here makes the generated summary report an outage that did not
+ # happen.
+ if query_error.get("type") == MISSING_QUERY_ERROR_TYPE:
+ results_summary = "No query to run"
+ else:
+ results_summary = "Query failed"
fallback_reason = "query_error"
else:
results_summary = "No results"
diff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_summary_fallbacks.py b/products/exports/backend/temporal/subscriptions/test_snapshot_summary_fallbacks.py
new file mode 100644
index 000000000000..c19626822501
--- /dev/null
+++ b/products/exports/backend/temporal/subscriptions/test_snapshot_summary_fallbacks.py
@@ -0,0 +1,32 @@
+from typing import Any
+
+from parameterized import parameterized
+
+from products.exports.backend.temporal.subscriptions.snapshot_activities import _build_states_from_content_snapshot
+from products.exports.backend.temporal.subscriptions.types import MISSING_QUERY_ERROR_TYPE
+
+
+def _snapshot_with(insight: dict[str, Any]) -> dict[str, Any]:
+ return {"insights": [{"id": 1, "name": "Pageviews", **insight}]}
+
+
+class TestSnapshotSummaryFallbacks:
+ @parameterized.expand(
+ [
+ (
+ "insight_stores_no_query",
+ {"query_error": {"type": MISSING_QUERY_ERROR_TYPE, "message": "Insight has no query"}},
+ "No query to run",
+ ),
+ (
+ "query_ran_and_failed",
+ {"query_error": {"type": "ExposedHogQLError", "message": "Unknown function: 'first_ever'"}},
+ "Query failed",
+ ),
+ ("query_ran_and_returned_nothing", {"query_results": {"result": []}}, "No results"),
+ ]
+ )
+ def test_summary_line(self, _name: str, insight: dict[str, Any], expected: str) -> None:
+ states = _build_states_from_content_snapshot(_snapshot_with(insight))
+
+ assert [state["results_summary"] for state in states] == [expected]
diff --git a/products/exports/backend/temporal/subscriptions/types.py b/products/exports/backend/temporal/subscriptions/types.py
index 25f9a6213a6f..b65faabd6366 100644
--- a/products/exports/backend/temporal/subscriptions/types.py
+++ b/products/exports/backend/temporal/subscriptions/types.py
@@ -11,6 +11,10 @@ from posthog.slo.types import SloConfig
# has no persisted details. The type still lands in diagnostics, logs, and error tracking.
UNDISCLOSED_QUERY_ERROR_TYPES = frozenset({"ClickHouseQueryMemoryLimitExceeded"})
+# The snapshot builder sets this query_error type when an insight stores no query at all. The
+# summary step reads it to tell an insight that cannot run apart from one that ran and failed.
+MISSING_QUERY_ERROR_TYPE = "missing_query"
+
class QueryErrorDetails(typing.TypedDict):
"""A failed query's type paired with its optional safe code and message."""