: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(max-ai): guard against None results in funnel formatters (#62313)
posthog[bot]9704615edd55
diff --git a/ee/hogai/context/insight/format/funnel.py b/ee/hogai/context/insight/format/funnel.pyindex e9abfbc149a8..22c85dea04e6 100644--- a/ee/hogai/context/insight/format/funnel.py+++ b/ee/hogai/context/insight/format/funnel.py@@ -60,7 +60,7 @@ class FunnelResultsFormatter:def __init__(self,query: AssistantFunnelsQuery | FunnelsQuery,- results: list[dict[str, Any]] | list[list[dict[str, Any]]] | dict[str, Any],+ results: list[dict[str, Any]] | list[list[dict[str, Any]]] | dict[str, Any] | None,team: Team,utc_now_datetime: datetime,):@@ -79,7 +79,7 @@ class FunnelResultsFormatter:def _format_steps(self) -> str:results = self._results- if len(results) == 0 or not isinstance(results, list):+ if not isinstance(results, list) or len(results) == 0:return "No data recorded for this time period."results = cast(list[dict[str, Any]] | list[list[dict[str, Any]]], results)@@ -100,7 +100,7 @@ class FunnelResultsFormatter:def _format_time_to_convert(self) -> str:results = self._results- if len(results) == 0 or not isinstance(results, dict):+ if not isinstance(results, dict) or len(results) == 0:return "No data recorded for this time period."matrix: list[list[Any]] = [@@ -114,7 +114,7 @@ class FunnelResultsFormatter:def _format_trends(self) -> str:results = self._results- if len(results) == 0 or not isinstance(results, list):+ if not isinstance(results, list) or len(results) == 0:return "No data recorded for this time period."results = cast(list[dict[str, Any]], results)diff --git a/ee/hogai/context/insight/format/test/test_funnel.py b/ee/hogai/context/insight/format/test/test_funnel.pyindex 2ba989b73a5b..dc1325826c95 100644--- a/ee/hogai/context/insight/format/test/test_funnel.py+++ b/ee/hogai/context/insight/format/test/test_funnel.py@@ -4,6 +4,8 @@ from typing import Anyfrom freezegun import freeze_timefrom posthog.test.base import BaseTest+from parameterized import parameterized+from posthog.schema import (AssistantDateRange,AssistantFunnelsEventsNode,@@ -110,6 +112,20 @@ class TestFunnelResultsFormatter(BaseTest):).format(),)+ @parameterized.expand(+ [+ (FunnelVizType.STEPS,),+ (FunnelVizType.TIME_TO_CONVERT,),+ (FunnelVizType.TRENDS,),+ ]+ )+ def test_funnels_none_results(self, viz_type: FunnelVizType):+ query = AssistantFunnelsQuery(series=[], funnelsFilter=AssistantFunnelsFilter(funnelVizType=viz_type))+ self.assertEqual(+ FunnelResultsFormatter(query, None, self.team, datetime.now()).format(),+ "No data recorded for this time period.",+ )+def test_funnels_breakdown(self):results = [{