: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): label ordinary trends aggregates with the resolved date range (#115922)
posthog[bot]f877ac9ed145
diff --git a/ee/hogai/context/insight/format/test/test_trends.py b/ee/hogai/context/insight/format/test/test_trends.pyindex 657666bd9a15..d32f99204218 100644--- a/ee/hogai/context/insight/format/test/test_trends.py+++ b/ee/hogai/context/insight/format/test/test_trends.py@@ -228,6 +228,41 @@ class TestTrendsResultsFormatter(BaseTest):"Date range|Aggregated value for $pageview\n2025-01-20 to 2025-01-22|993",)+ @parameterized.expand(+ [+ (+ "iso_strings_crossing_local_midnight",+ {"date_from": "2026-10-12T23:41:45-07:00", "date_to": "2026-10-13T00:41:49-07:00"},+ "2026-10-12 23:41:45-07:00 to 2026-10-13 00:41:49-07:00",+ ),+ (+ "datetimes_with_microseconds",+ {+ "date_from": datetime(2026, 10, 12, 23, 41, 45, 123456, tzinfo=ZoneInfo("America/Los_Angeles")),+ "date_to": datetime(2026, 10, 13, 0, 41, 49, 999999, tzinfo=ZoneInfo("America/Los_Angeles")),+ },+ "2026-10-12 23:41:45-07:00 to 2026-10-13 00:41:49-07:00",+ ),+ ]+ )+ def test_trends_aggregated_value_uses_resolved_date_range(self, _name, resolved_date_range, expected_range):+ results = [+ {+ "data": [],+ "days": [],+ "count": 0,+ "aggregated_value": 82,+ "label": "$pageview",+ "action": {"days": ["2026-10-12 00:00:00-07:00", "2026-10-13 00:00:00-07:00"]},+ }+ ]+ self.assertEqual(+ TrendsResultsFormatter(+ AssistantTrendsQuery(series=[]), results, resolved_date_range=resolved_date_range+ ).format(),+ f"Date range|Aggregated value for $pageview\n{expected_range}|82",+ )+def test_trends_aggregated_values(self):results = [{diff --git a/ee/hogai/context/insight/format/trends.py b/ee/hogai/context/insight/format/trends.pyindex d51cc05bf1c7..90f0ad3b0381 100644--- a/ee/hogai/context/insight/format/trends.py+++ b/ee/hogai/context/insight/format/trends.py@@ -73,7 +73,9 @@ class TrendsResultsFormatter:template = f"Previous period:\n{previous_formatted}\n\nCurrent period:\n{current_formatted}"return template- return self._format_results(results)+ # Only one period is present here, so label aggregated rows with that period's resolved range.+ resolved_date_range = self._resolved_compare_date_range if previous else self._resolved_date_range+ return self._format_results(results, resolved_date_range)def _format_aggregated_values(self, results: list[dict[str, Any]], resolved_date_range: Optional[dict[str, Any]] = None