: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(insights): convert legacy insights whose breakdowns list is empty (#89128)
Thomas Obermüller133857154211
diff --git a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/filter_to_query.pyindex 883e4c5b2b28..baec7894cfe5 100644--- a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py+++ b/posthog/hogql_queries/legacy_compatibility/filter_to_query.py@@ -415,7 +415,9 @@ def _breakdown_filter(_filter: dict):if breakdownFilter["breakdown_type"] == "events":breakdownFilter["breakdown_type"] = "event"- if _filter.get("breakdowns") is not None:+ # An empty `breakdowns` carries no breakdown at all. The trends branch below already ignores it,+ # and the single-breakdown branch would otherwise read it as a multi-breakdown and refuse to convert.+ if _filter.get("breakdowns"):if _insight_type(_filter) == "TRENDS":# Trends support multiple breakdownsbreakdowns = []diff --git a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.pyindex 2e7e4338b529..769778e743b0 100644--- a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py+++ b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py@@ -3,6 +3,8 @@ from typing import Any, castimport pytestfrom posthog.test.base import BaseTest+from parameterized import parameterized+from posthog.schema import (ActionsNode,AggregationAxisFormat,@@ -1677,43 +1679,30 @@ class TestFilterToQuery(BaseTest):),)- def test_funnels_multiple_breakdowns(self):- filter: dict[str, Any] = {- "insight": "FUNNELS",- "breakdowns": [- {"type": "session", "property": "$session_duration"},- ],- }-- query = filter_to_query(filter)-- assert isinstance(query, FunnelsQuery)- self.assertEqual(- query.breakdownFilter,- BreakdownFilter(- breakdown="$session_duration",- breakdown_type=BreakdownType.SESSION,+ @parameterized.expand(+ [+ (+ "single",+ [{"type": "session", "property": "$session_duration"}],+ BreakdownFilter(breakdown="$session_duration", breakdown_type=BreakdownType.SESSION),),- )-- def test_funnels_multiple_breakdowns_no_breakdown_type(self):- filter: dict[str, Any] = {- "insight": "FUNNELS",- "breakdowns": [- {"property": "prop"},- ],- }+ (+ "no_breakdown_type",+ [{"property": "prop"}],+ BreakdownFilter(breakdown="prop", breakdown_type=BreakdownType.EVENT),+ ),+ # An empty list used to raise "found more than one breakdown", so the insight never+ # converted. It now lands where an absent `breakdowns` key lands: no breakdown property.+ ("empty", [], BreakdownFilter(breakdown_type=BreakdownType.EVENT)),+ ]+ )+ def test_funnels_breakdowns(self, _name, breakdowns, expected):+ filter: dict[str, Any] = {"insight": "FUNNELS", "breakdowns": breakdowns}query = filter_to_query(filter)assert isinstance(query, FunnelsQuery)- self.assertEqual(- query.breakdownFilter,- BreakdownFilter(- breakdown="prop",- breakdown_type=BreakdownType.EVENT,- ),- )+ self.assertEqual(query.breakdownFilter, expected)def test_funnels_use_first_time_for_user_math(self):filter: dict[str, Any] = {