: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
feat(warehouse_sources): support Klaviyo API version 2026-07-15 (#71530)
Daniel RCb4a8923c5981
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex bd4dbf48fef4..6914973b407d 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -72,3 +72,5 @@ After you finish a version-update or deprecation PR using this skill, **append w- Notion 2026-03-11: for read-only syncs a new version is often header-only — its breaking changes (`archived`->`in_trash`, `transcription`->`meeting_notes` block type, `after`->`position` on _append_ block children) only touch response fields or write paths we never call, so with an auto-inferred schema the sole dispatch is threading the resolved version into the request header. No per-version module needed.- When the request layer hardcodes the version as a module constant (e.g. `NOTION_VERSION`), the dispatch is: add a param through the client/session builders (`notion_source` -> `get_rows` -> `_build_session` -> `_get_headers`), pass `self.resolve_api_version(inputs.api_version)` from `source_for_pipeline`, and give the standalone `validate_credentials(token, api_version)` `self.default_version` (creation-time, version-agnostic probe).- Test pattern that stayed cheap: parameterize the header builder over supported versions (header carries requested version) + mock `notion_source` in the source module and assert `call_args.kwargs["api_version"]` for none/legacy/new pins (resolution + threading in one).+- Auto-inferred-schema sources (`has_managed_hogql_schema=False`) turn new attributes into new columns automatically, so a version bump whose breaking changes only touch fields the source never reads needs no data/schema transform — the repin migration is a plain idempotent `api_version` UPDATE. Verify field-by-field against the changelog instead of assuming a date bump is breaking.+- A repin migration's reverse must be a no-op: after repinning, rows on the new default are indistinguishable from natively-created ones, so a blanket downgrade would clobber legitimate native pins (same reasoning as the 0075 api_version backfill).diff --git a/products/warehouse_sources/backend/migrations/0081_repin_klaviyo_api_version.py b/products/warehouse_sources/backend/migrations/0081_repin_klaviyo_api_version.pynew file mode 100644index 000000000000..4bf5ba8cce9f--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0081_repin_klaviyo_api_version.py@@ -0,0 +1,34 @@+from django.db import migrations++# Klaviyo's 2024-10-15 revision entered its deprecated phase and retires ~2026-10-15 (falling+# forward / returning 410 thereafter). Repin source-level pins onto the current 2026-07-15 revision.+# The endpoints/fields this source reads are backward compatible across the two revisions, so the+# repin needs no data/schema transform — only the pin moves.+KLAVIYO_SOURCE_TYPE = "Klaviyo"+DEPRECATED_VERSION = "2024-10-15"+TARGET_VERSION = "2026-07-15"+++def repin_klaviyo_api_version(apps, schema_editor):+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")++ # Only touch source-level pins still on the deprecated revision. NULL pins already resolve to the+ # source's `default_version` (now 2026-07-15), so they need no update. Filtering on the exact old+ # value keeps this idempotent — a re-run matches nothing. Schema-level overrides+ # (`ExternalDataSchema.api_version`) are intentionally customer-pinned and are left untouched.+ ExternalDataSource.objects.filter(source_type=KLAVIYO_SOURCE_TYPE, api_version=DEPRECATED_VERSION).update(+ api_version=TARGET_VERSION+ )+++class Migration(migrations.Migration):+ dependencies = [+ ("warehouse_sources", "0080_externaldatasource_auto_sync_new_schemas_and_more"),+ ]++ operations = [+ # Reverse is a no-op: once repinned, a source on 2026-07-15 is indistinguishable from one+ # natively created on the new default, so downgrading every 2026-07-15 row would clobber+ # legitimate native pins.+ migrations.RunPython(repin_klaviyo_api_version, migrations.RunPython.noop, elidable=True),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 987ebf16dee4..3824d88323ce 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0080_externaldatasource_auto_sync_new_schemas_and_more+0081_repin_klaviyo_api_versiondiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/constants.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/constants.pynew file mode 100644index 000000000000..720cbeb4aff7--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/constants.py@@ -0,0 +1,5 @@+# Klaviyo revisions are date-based API snapshots. One constant per revision so the source's+# version declaration (`KlaviyoSource.supported_versions`) and the request layer (the `revision`+# header) share a single label — never parsed or ordered.+KLAVIYO_API_VERSION_2024_10_15 = "2024-10-15"+KLAVIYO_API_VERSION_2026_07_15 = "2026-07-15"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/klaviyo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/klaviyo.pyindex 5cb10045ebf7..fc5b6d19a269 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/klaviyo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/klaviyo.py@@ -11,6 +11,9 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelinefrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager+from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.constants import (+ KLAVIYO_API_VERSION_2026_07_15,+)from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.settings import (KLAVIYO_ENDPOINTS,KlaviyoEndpointConfig,@@ -117,10 +120,12 @@ def _build_url(base_url: str, params: dict[str, Any]) -> str:return f"{base_url}?{'&'.join(parts)}"-def _get_headers(api_key: str) -> dict[str, str]:+def _get_headers(api_key: str, revision: str = KLAVIYO_API_VERSION_2026_07_15) -> dict[str, str]:+ # `revision` is the pinned vendor API version, threaded from the source instance's resolved pin.+ # Defaults to the current version for credential validation, which runs before any row is pinned.return {"Authorization": f"Klaviyo-API-Key {api_key}",- "revision": "2024-10-15",+ "revision": revision,"Accept": "application/json",}@@ -311,12 +316,13 @@ def get_rows(endpoint: str,logger: FilteringBoundLogger,resumable_source_manager: ResumableSourceManager[KlaviyoResumeConfig],+ api_version: str = KLAVIYO_API_VERSION_2026_07_15,should_use_incremental_field: bool = False,db_incremental_field_last_value: Any = None,incremental_field: str | None = None,) -> Iterator[Any]:config = KLAVIYO_ENDPOINTS[endpoint]- headers = _get_headers(api_key)+ headers = _get_headers(api_key, api_version)batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)# One session reused across every page (and, for fan-out, every list) so urllib3 keeps the# connection alive instead of re-handshaking per request.@@ -377,6 +383,7 @@ def klaviyo_source(endpoint: str,logger: FilteringBoundLogger,resumable_source_manager: ResumableSourceManager[KlaviyoResumeConfig],+ api_version: str = KLAVIYO_API_VERSION_2026_07_15,should_use_incremental_field: bool = False,db_incremental_field_last_value: Optional[Any] = None,incremental_field: str | None = None,@@ -390,6 +397,7 @@ def klaviyo_source(endpoint=endpoint,logger=logger,resumable_source_manager=resumable_source_manager,+ api_version=api_version,should_use_incremental_field=should_use_incremental_field,db_incremental_field_last_value=db_incremental_field_last_value,incremental_field=incremental_field,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/source.pyindex 14f252271274..d9f66a512737 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/source.py@@ -1,3 +1,4 @@+from datetime import datefrom typing import Optional, castfrom posthog.schema import (@@ -13,7 +14,11 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelineSourceInputs,SourceResponse,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ FieldType,+ ResumableSource,+ VersionDeprecation,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (CanonicalDescriptions,)@@ -21,6 +26,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.regfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import SourceSchemafrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import KlaviyoSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.constants import (+ KLAVIYO_API_VERSION_2024_10_15,+ KLAVIYO_API_VERSION_2026_07_15,+)from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.klaviyo import (KlaviyoResumeConfig,klaviyo_source,@@ -36,9 +45,11 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass KlaviyoSource(ResumableSource[KlaviyoSourceConfig, KlaviyoResumeConfig]):- supported_versions = ("2024-10-15",)- default_version = "2024-10-15"+ supported_versions = (KLAVIYO_API_VERSION_2024_10_15, KLAVIYO_API_VERSION_2026_07_15)+ default_version = KLAVIYO_API_VERSION_2026_07_15api_docs_url = "https://developers.klaviyo.com"+ # Klaviyo retires a revision two years after release, falling forward / returning 410 thereafter.+ deprecated_versions = (VersionDeprecation(version=KLAVIYO_API_VERSION_2024_10_15, sunset_at=date(2026, 10, 15)),)lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@@ -165,6 +176,7 @@ Make sure to grant the following read permissions:endpoint=inputs.schema_name,logger=inputs.logger,resumable_source_manager=resumable_source_manager,+ api_version=self.resolve_api_version(inputs.api_version),should_use_incremental_field=inputs.should_use_incremental_field,db_incremental_field_last_value=inputs.db_incremental_field_last_valueif inputs.should_use_incremental_fielddiff --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 d12ebed1aab4..4e7f547bd522 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@@ -500,3 +500,39 @@ class TestSourceResponseSortMode:resumable_source_manager=MagicMock(),)assert response.sort_mode == expected+++class TestApiVersionThreadsToRevisionHeader:+ @parameterized.expand([("2024-10-15",), ("2026-07-15",)])+ def test_pinned_version_reaches_revision_header(self, api_version: str) -> None:+ # The resolved pin must reach Klaviyo's `revision` header, or a source pinned to a supported+ # revision would silently sync against whatever version the request layer hardcodes.+ captured: dict[str, str] = {}++ def fake_fetch(session: Any, url: str, headers: dict[str, str], logger: Any) -> dict:+ captured.update(headers)+ return {"data": [], "links": {"next": None}}++ with patch.object(klaviyo, "_fetch_page", fake_fetch):+ list(+ get_rows(+ api_key="pk_test",+ endpoint="events",+ logger=MagicMock(),+ resumable_source_manager=_FakeResumableManager(), # type: ignore[arg-type]+ api_version=api_version,+ )+ )++ assert captured["revision"] == api_version+++class TestVersionDeprecation:+ def test_2024_revision_deprecated_with_sunset_and_current_is_not(self) -> None:+ # The generic in-product warning keys off this metadata; the registry invariant test checks+ # the set relationships but not the specific sunset date this PR pins.+ source = KlaviyoSource()+ deprecation = source.get_version_deprecation("2024-10-15")+ assert deprecation is not None+ assert deprecation.sunset_at == date(2026, 10, 15)+ assert source.get_version_deprecation("2026-07-15") is None