: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(data-warehouse): use Klaviyo per-endpoint max page sizes for list_profiles (#65413)
Luke Belton5c861256d52c
diff --git a/posthog/temporal/data_imports/sources/klaviyo/klaviyo.py b/posthog/temporal/data_imports/sources/klaviyo/klaviyo.pyindex d50eea7cd2eb..668c90c44d3e 100644--- a/posthog/temporal/data_imports/sources/klaviyo/klaviyo.py+++ b/posthog/temporal/data_imports/sources/klaviyo/klaviyo.py@@ -184,7 +184,8 @@ def _fetch_page(def _iter_list_ids(session: requests.Session, headers: dict[str, str], logger: FilteringBoundLogger) -> Iterator[str]:"""Page through /lists and yield each list's id, following the cursor links."""- url = _build_url(f"{KLAVIYO_BASE_URL}/lists", {"page[size]": 100})+ # Klaviyo caps the /lists endpoint at a page size of 10 (larger values 400).+ url = _build_url(f"{KLAVIYO_BASE_URL}/lists", {"page[size]": 10})while True:data = _fetch_page(session, url, headers, logger)for item in data.get("data", []):@@ -224,8 +225,9 @@ def _get_list_profile_rows(logger.debug(f"Klaviyo: resuming list_profiles from list_id={resume.list_id}, url={resume_url}")for index, list_id in enumerate(remaining):+ # The relationships endpoint caps page size at 100 (larger values 400).url = resume_url or _build_url(- f"{KLAVIYO_BASE_URL}/lists/{list_id}/relationships/profiles", {"page[size]": 1000}+ f"{KLAVIYO_BASE_URL}/lists/{list_id}/relationships/profiles", {"page[size]": 100})resume_url = None # only the resumed-into list uses the saved URL; the rest start freshdiff --git a/posthog/temporal/data_imports/sources/klaviyo/test_klaviyo.py b/posthog/temporal/data_imports/sources/klaviyo/test_klaviyo.pyindex 1f7c379a3acc..3705fcbbc4fe 100644--- a/posthog/temporal/data_imports/sources/klaviyo/test_klaviyo.py+++ b/posthog/temporal/data_imports/sources/klaviyo/test_klaviyo.py@@ -248,15 +248,15 @@ class TestListProfilesFanOut:def test_fans_out_over_every_list_into_membership_rows(self, monkeypatch: Any) -> None:pages = {- "https://a.klaviyo.com/api/lists?page[size]=100": {+ "https://a.klaviyo.com/api/lists?page[size]=10": {"data": [{"id": "L1"}, {"id": "L2"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P1"}, {"type": "profile", "id": "P2"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L2/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/L2/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P3"}],"links": {"next": None},},@@ -271,11 +271,11 @@ class TestListProfilesFanOut:def test_follows_membership_pagination(self, monkeypatch: Any) -> None:next_url = "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[cursor]=abc"pages = {- "https://a.klaviyo.com/api/lists?page[size]=100": {+ "https://a.klaviyo.com/api/lists?page[size]=10": {"data": [{"id": "L1"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P1"}],"links": {"next": next_url},},@@ -292,11 +292,11 @@ class TestListProfilesFanOut:def test_resume_from_deleted_list_restarts_from_first(self, monkeypatch: Any) -> None:pages = {- "https://a.klaviyo.com/api/lists?page[size]=100": {+ "https://a.klaviyo.com/api/lists?page[size]=10": {"data": [{"id": "L1"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P1"}],"links": {"next": None},},@@ -308,16 +308,16 @@ class TestListProfilesFanOut:def test_list_deleted_mid_fan_out_is_skipped(self, monkeypatch: Any) -> None:not_found = requests.HTTPError(response=_response_with_status(404))pages = {- "https://a.klaviyo.com/api/lists?page[size]=100": {+ "https://a.klaviyo.com/api/lists?page[size]=10": {"data": [{"id": "L1"}, {"id": "GONE"}, {"id": "L2"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P1"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/GONE/relationships/profiles?page[size]=1000": not_found,- "https://a.klaviyo.com/api/lists/L2/relationships/profiles?page[size]=1000": {+ "https://a.klaviyo.com/api/lists/GONE/relationships/profiles?page[size]=100": not_found,+ "https://a.klaviyo.com/api/lists/L2/relationships/profiles?page[size]=100": {"data": [{"type": "profile", "id": "P2"}],"links": {"next": None},},@@ -331,11 +331,11 @@ class TestListProfilesFanOut:def test_non_404_http_error_propagates(self, monkeypatch: Any) -> None:server_error = requests.HTTPError(response=_response_with_status(500))pages = {- "https://a.klaviyo.com/api/lists?page[size]=100": {+ "https://a.klaviyo.com/api/lists?page[size]=10": {"data": [{"id": "L1"}],"links": {"next": None},},- "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=1000": server_error,+ "https://a.klaviyo.com/api/lists/L1/relationships/profiles?page[size]=100": server_error,}with pytest.raises(requests.HTTPError):self._collect(_FakeResumableManager(), monkeypatch, pages)