: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(klaviyo): use last_52_weeks timeframe for weekly-interval series reports (#91940)
Tom Owersf22999ca547b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.pyindex fd0037b0794a..d82f7d903a8d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py@@ -120,14 +120,18 @@ VALUES_REPORT_STATISTICS = [# The widest window Klaviyo's reporting API allows is one year.VALUES_REPORT_TIMEFRAME_KEY = "last_365_days"+# Klaviyo caps weekly-interval series reports at exactly 52 weeks. last_365_days (365 days) exceeds+# that by one day (52 * 7 = 364), so series reports need their own shorter timeframe key.+SERIES_REPORT_TIMEFRAME_KEY = "last_52_weeks"+# Series reports bucket the window by an interval. Klaviyo caps an hourly interval at 7 days and a-# daily one at 60, so a weekly interval is the finest that spans the full one-year window (52 rows-# per grouping).+# daily one at 60, so a weekly interval gives the fullest view within the 52-week series limit+# (52 rows per grouping).SERIES_REPORT_INTERVAL = "weekly"# A series row is one time bucket, so date_time is a real per-row cursor even though the request# always asks for the whole window. Selecting it makes the sync merge on the primary key rather than-# replace the table, so buckets that age out of Klaviyo's 365-day window stay in the warehouse while+# replace the table, so buckets that age out of Klaviyo's 52-week window stay in the warehouse while# the buckets still inside it keep getting corrected.SERIES_REPORT_INCREMENTAL_FIELDS: list[IncrementalField] = [{@@ -521,13 +525,13 @@ KLAVIYO_ENDPOINTS: dict[str, KlaviyoEndpointConfig] = {values_report=KlaviyoValuesReportConfig(report_type="flow-series-report",statistics=VALUES_REPORT_STATISTICS,- timeframe_key=VALUES_REPORT_TIMEFRAME_KEY,+ timeframe_key=SERIES_REPORT_TIMEFRAME_KEY,group_by=["flow_id", "flow_message_id", "send_channel"],interval=SERIES_REPORT_INTERVAL,),description=(- "Klaviyo's own flow-message performance statistics bucketed by week over the last 365 "- "days, one row per flow message per week. Weeks stay in the table after Klaviyo stops "+ "Klaviyo's own flow-message performance statistics bucketed by week over the last 52 "+ "weeks, one row per flow message per week. Weeks stay in the table after Klaviyo stops ""returning them"),),@@ -578,14 +582,14 @@ KLAVIYO_ENDPOINTS: dict[str, KlaviyoEndpointConfig] = {values_report=KlaviyoValuesReportConfig(report_type="form-series-report",statistics=FORM_REPORT_STATISTICS,- timeframe_key=VALUES_REPORT_TIMEFRAME_KEY,+ timeframe_key=SERIES_REPORT_TIMEFRAME_KEY,group_by=["form_id"],interval=SERIES_REPORT_INTERVAL,requires_conversion_metric=False,),description=(- "Klaviyo's own signup-form performance statistics bucketed by week over the last 365 "- "days, one row per form per week. Weeks stay in the table after Klaviyo stops returning "+ "Klaviyo's own signup-form performance statistics bucketed by week over the last 52 "+ "weeks, one row per form per week. Weeks stay in the table after Klaviyo stops returning ""them"),),@@ -599,13 +603,13 @@ KLAVIYO_ENDPOINTS: dict[str, KlaviyoEndpointConfig] = {values_report=KlaviyoValuesReportConfig(report_type="segment-series-report",statistics=SEGMENT_REPORT_STATISTICS,- timeframe_key=VALUES_REPORT_TIMEFRAME_KEY,+ timeframe_key=SERIES_REPORT_TIMEFRAME_KEY,group_by=[],interval=SERIES_REPORT_INTERVAL,requires_conversion_metric=False,),description=(- "Klaviyo's own segment membership statistics bucketed by week over the last 365 days, "+ "Klaviyo's own segment membership statistics bucketed by week over the last 52 weeks, ""one row per segment per week. Weeks stay in the table after Klaviyo stops returning ""them"),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.pyindex bb3f7aaaaf96..7c6654dcbcc0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py@@ -29,6 +29,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.kl)from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.settings import (KLAVIYO_ENDPOINTS,+ SERIES_REPORT_TIMEFRAME_KEY,KlaviyoEndpointConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.source import KlaviyoSource@@ -1097,7 +1098,7 @@ class TestReportVariants:"send_channel": "email","date_time": "2026-01-05T00:00:00+00:00","opens": 1,- "timeframe_key": "last_365_days",+ "timeframe_key": SERIES_REPORT_TIMEFRAME_KEY,"conversion_metric_id": "M_ORDER",},{@@ -1106,7 +1107,7 @@ class TestReportVariants:"send_channel": "email","date_time": "2026-01-12T00:00:00+00:00","opens": 2,- "timeframe_key": "last_365_days",+ "timeframe_key": SERIES_REPORT_TIMEFRAME_KEY,"conversion_metric_id": "M_ORDER",},]@@ -1163,12 +1164,16 @@ class TestReportVariants:def test_series_reports_key_on_the_time_bucket(self, endpoint: str) -> None:# Without date_time in the primary key, the ~52 weekly rows per grouping collapse to one on# merge, silently discarding the whole time series. Without date_time as a cursor the table- # syncs full refresh, so every sync rebuilds it from Klaviyo's rolling 365-day window and- # drops the weeks that have since left it, which no later sync can fetch again.+ # syncs full refresh, so every sync rebuilds it from Klaviyo's rolling window and drops the+ # weeks that have since left it, which no later sync can fetch again.config = KLAVIYO_ENDPOINTS[endpoint]assert "date_time" in config.primary_keysassert [f["field"] for f in config.incremental_fields] == ["date_time"]assert config.default_incremental_field == "date_time"+ # Klaviyo caps weekly-interval series reports at 52 weeks; last_365_days (365 days) exceeds+ # that by one day and causes a 400. All series endpoints must use the shorter key.+ assert config.values_report is not None+ assert config.values_report.timeframe_key == SERIES_REPORT_TIMEFRAME_KEYclass TestEndpointRequestParams: