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(llma): guard humanize_breakdown_label against None series label (#70485)

jake sciotto69c23007fe73
diff --git a/ee/hogai/context/insight/format/test/test_trends.py b/ee/hogai/context/insight/format/test/test_trends.py
index 091e456f40d9..d9cf7149cf46 100644
--- a/ee/hogai/context/insight/format/test/test_trends.py
+++ b/ee/hogai/context/insight/format/test/test_trends.py
@@ -188,6 +188,25 @@ class TestTrendsResultsFormatter(BaseTest):
"so their values are incomplete. Timezone: UTC.",
)
+ def test_trends_labelless_series(self):
+ # A series with no label, custom_name, or breakdown_value used to crash the formatter with
+ # `AttributeError: 'NoneType' object has no attribute 'replace'`. It should render as an
+ # empty label instead.
+ results = [
+ {
+ "data": [242, 46, 0],
+ "labels": ["23-Jan-2025", "24-Jan-2025", "25-Jan-2025"],
+ "days": ["2025-01-23", "2025-01-24", "2025-01-25"],
+ "count": 288,
+ "label": None,
+ }
+ ]
+
+ self.assertEqual(
+ TrendsResultsFormatter(AssistantTrendsQuery(series=[]), results).format(),
+ "Date|\n2025-01-23|242\n2025-01-24|46\n2025-01-25|0",
+ )
+
def test_trends_aggregated_value(self):
results = [
{
diff --git a/posthog/hogql_queries/insights/utils/breakdowns.py b/posthog/hogql_queries/insights/utils/breakdowns.py
index c4a3077a5e12..92b85407f764 100644
--- a/posthog/hogql_queries/insights/utils/breakdowns.py
+++ b/posthog/hogql_queries/insights/utils/breakdowns.py
@@ -17,10 +17,15 @@ ALL_USERS_COHORT_ID = 0
NOT_IN_COHORT_ID = 2**52
-def humanize_breakdown_label(label: str) -> str:
+def humanize_breakdown_label(label: str | None) -> str:
"""Swap the internal breakdown sentinels for their display strings. The sentinels are globally
unique tokens, so a substring replace covers every label shape — standalone, action-prefixed
- ("signed_up - <sentinel>"), and "::"-joined multi-breakdown values — without fragile splitting."""
+ ("signed_up - <sentinel>"), and "::"-joined multi-breakdown values — without fragile splitting.
+
+ A series can reach here with no label at all (no name, custom_name, or breakdown_value), so coerce
+ a missing label to an empty string rather than crashing on `None.replace(...)`."""
+ if label is None:
+ return ""
return label.replace(BREAKDOWN_OTHER_STRING_LABEL, BREAKDOWN_OTHER_DISPLAY).replace(
BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_NULL_DISPLAY
)
diff --git a/posthog/hogql_queries/insights/utils/test/test_breakdowns.py b/posthog/hogql_queries/insights/utils/test/test_breakdowns.py
index b01744b8b428..845bd762098c 100644
--- a/posthog/hogql_queries/insights/utils/test/test_breakdowns.py
+++ b/posthog/hogql_queries/insights/utils/test/test_breakdowns.py
@@ -63,7 +63,9 @@ def test_breakdown_presence_helpers(
("Chrome", "Chrome"),
# a normal label containing " - " must pass through untouched (no fragile splitting)
("Signed up - paid", "Signed up - paid"),
+ # a labelless series (no name, custom_name, or breakdown_value) must not crash
+ (None, ""),
],
)
-def test_humanize_breakdown_label(label: str, expected: str) -> None:
+def test_humanize_breakdown_label(label: str | None, expected: str) -> None:
assert humanize_breakdown_label(label) == expected