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(hogql): return 400 not 500 on malformed actors query shape (#87459)

posthog[bot]9aeff9d25e94
diff --git a/posthog/hogql_queries/insights/insight_actors_query_runner.py b/posthog/hogql_queries/insights/insight_actors_query_runner.py
index 41383e7f2c57..027806d3bebd 100644
--- a/posthog/hogql_queries/insights/insight_actors_query_runner.py
+++ b/posthog/hogql_queries/insights/insight_actors_query_runner.py
@@ -20,6 +20,7 @@ from posthog.schema import (
from posthog.hogql import ast
from posthog.hogql.constants import LimitContext
+from posthog.hogql.errors import ExposedHogQLError
from posthog.hogql.query import execute_hogql_query
from posthog.hogql.timings import HogQLTimings
@@ -164,13 +165,13 @@ class InsightActorsQueryRunner(AnalyticsQueryRunner[HogQLQueryResponse]):
return cast(RetentionQueryRunner, self.source_runner).group_type_index
if isinstance(self.source_runner, FunnelCorrelationQueryRunner):
- assert isinstance(self.query, FunnelCorrelationActorsQuery)
- assert isinstance(self.query.source, FunnelCorrelationQuery)
+ if not isinstance(self.query.source, FunnelCorrelationQuery):
+ raise ExposedHogQLError("Funnel correlation actors query requires a FunnelCorrelationQuery source")
return self.query.source.source.source.aggregation_group_type_index
if isinstance(self.source_runner, FunnelsQueryRunner):
- assert isinstance(self.query, FunnelsActorsQuery)
- assert isinstance(self.query.source, FunnelsQuery)
+ if not isinstance(self.query.source, FunnelsQuery):
+ raise ExposedHogQLError("Funnels actors query requires a FunnelsQuery source")
return self.query.source.aggregation_group_type_index
if isinstance(self.source_runner, LifecycleQueryRunner):
diff --git a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py
index 86dc9b9271ba..9e8e81552139 100644
--- a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py
+++ b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py
@@ -15,6 +15,7 @@ from posthog.schema import (
BaseMathType,
DateRange,
EventsNode,
+ FunnelsQuery,
HogQLQueryModifiers,
InsightActorsQuery,
MathGroupTypeIndex,
@@ -511,3 +512,16 @@ class TestInsightActorsQueryRunner(ClickhouseTestMixin, APIBaseTest):
runner = InsightActorsQueryRunner(query=query, team=self.team)
self.assertEqual(runner.group_type_index, 2)
+
+ def test_group_type_index_property_plain_insight_actors_wrapping_funnels(self):
+ # A plain InsightActorsQuery can wrap a FunnelsQuery. group_type_index must read the source
+ # aggregation instead of failing on the wrapper node type.
+ query = InsightActorsQuery(
+ source=FunnelsQuery(
+ aggregation_group_type_index=0,
+ series=[EventsNode(event="$pageview"), EventsNode(event="$pageview")],
+ )
+ )
+
+ runner = InsightActorsQueryRunner(query=query, team=self.team)
+ self.assertEqual(runner.group_type_index, 0)