: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 impact.com API version 14 (#80092)
Tom Owers171524e0dc7a
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex ddac8c1c4b84..3cc02aa49275 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -81,6 +81,7 @@ Add it when any of these hold:- Credential-validation paths (`validate_credentials`, permission probes) run at creation time with no row pin; they may use the default/legacy version. Changing them is optional per version bump — verify the vendor accepts the validation calls under the new version before switching them.- A passing credential probe is not evidence sync works — the probe hits one endpoint, `get_rows` hits the rest; when they diverge per version, the probe passes while every table 404s.- Version → header/path maps must cover every supported label — a `.get()` fallthrough silently sends no version header (tracking "latest", the drift this framework prevents). Assert coverage or raise.+- First-time versioning of a source that sends no version selector today: keep the pre-existing label (the `UNVERSIONED_API_VERSION` default) sending nothing, and add the selector only for the new dated label. That preserves already-pinned rows byte-for-byte, and pinning the new default is the point — the no-selector path was tracking the vendor account's configured version, which is the drift. This is not the fallthrough bug above: the empty selector here is deliberate and belongs to one specific legacy label, not a `.get()` miss.- Parallel version-bump PRs grab the same next migration number; the second to merge becomes a conflicting leaf and `ci:preflight` blocks it. Check `max_migration.txt` and renumber.- Don't regenerate schemas for existing customers as part of a version add; schema changes only apply to rows repinned via the (human-run) migration.- Discovery diffs under the SOURCE pin (`sync_new_schemas`, `refresh_schemas`, bulk sync-defaults). A schema-level `api_version` override on a version whose table set differs from the source's version can be disabled/soft-deleted by that diff — keep overrides to short verification windows, not as a long-term way to hold one table on another version.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/impact.py b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/impact.pyindex 96688a969186..391df0a7e292 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/impact.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/impact.py@@ -11,7 +11,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.httfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.impact.settings import (+ IMPACT_API_VERSION_LEGACY,IMPACT_ENDPOINTS,+ IMPACT_VERSION_HEADER,MAX_LOOKBACK_DAYS,MAX_WINDOW_DAYS,ImpactEndpointConfig,@@ -32,11 +34,15 @@ class ImpactResumeConfig:window_start: Optional[str] = None-def _get_session(account_sid: str, auth_token: str) -> requests.Session:+def _get_session(account_sid: str, auth_token: str, api_version: str = IMPACT_API_VERSION_LEGACY) -> requests.Session:session = make_tracked_session(redact_values=(auth_token,))session.auth = HTTPBasicAuth(account_sid, auth_token)# Impact.com returns XML unless explicitly asked for JSON.session.headers["Accept"] = "application/json"+ # The legacy label sends no version header, so it keeps tracking the account's configured+ # default; a dated label pins the response shape via the header.+ if api_version != IMPACT_API_VERSION_LEGACY:+ session.headers[IMPACT_VERSION_HEADER] = api_versionreturn session@@ -51,9 +57,9 @@ def _fetch(return response.json()-def validate_credentials(account_sid: str, auth_token: str) -> bool:+def validate_credentials(account_sid: str, auth_token: str, api_version: str = IMPACT_API_VERSION_LEGACY) -> bool:try:- session = _get_session(account_sid, auth_token)+ session = _get_session(account_sid, auth_token, api_version)response = session.get(f"{BASE_URL}/Advertisers/{account_sid}/Campaigns",params={"PageSize": 1},@@ -311,9 +317,10 @@ def get_rows(resumable_source_manager: ResumableSourceManager[ImpactResumeConfig],should_use_incremental_field: bool = False,db_incremental_field_last_value: Any = None,+ api_version: str = IMPACT_API_VERSION_LEGACY,) -> Iterator[list[dict[str, Any]]]:config = IMPACT_ENDPOINTS[endpoint]- session = _get_session(account_sid, auth_token)+ session = _get_session(account_sid, auth_token, api_version)if config.nested is not None:yield from _get_rows_nested(session, account_sid, config, logger, resumable_source_manager)@@ -350,6 +357,7 @@ def impact_source(resumable_source_manager: ResumableSourceManager[ImpactResumeConfig],should_use_incremental_field: bool = False,db_incremental_field_last_value: Optional[Any] = None,+ api_version: str = IMPACT_API_VERSION_LEGACY,) -> SourceResponse:config = IMPACT_ENDPOINTS[endpoint]@@ -363,6 +371,7 @@ def impact_source(resumable_source_manager=resumable_source_manager,should_use_incremental_field=should_use_incremental_field,db_incremental_field_last_value=db_incremental_field_last_value,+ api_version=api_version,),primary_keys=config.primary_keys,partition_mode="datetime" if config.partition_key else None,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/settings.pyindex b8e2e94bf9b8..31b7c34bef78 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/settings.py@@ -1,8 +1,21 @@from dataclasses import dataclass, fieldfrom typing import Optional+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType+# impact.com's Brand API selects a version via the `IR-Version` header (or `IrVersion` query param),+# carrying a dated integer label — see+# https://integrations.impact.com/brand-api-reference/readme/versioning. The legacy label predates+# our pinning any version and sends no header, so those syncs keep tracking the account's configured+# default exactly as before. `"14"` (released 2026-06-01) pins the response shape explicitly.+IMPACT_VERSION_HEADER = "IR-Version"+IMPACT_API_VERSION_LEGACY = UNVERSIONED_API_VERSION+IMPACT_API_VERSION_14 = "14"+# Oldest→newest; the last entry is the default (enforced by test_source_versions.py).+SUPPORTED_API_VERSIONS = (IMPACT_API_VERSION_LEGACY, IMPACT_API_VERSION_14)+DEFAULT_API_VERSION = IMPACT_API_VERSION_14+# Impact rejects an Actions StartDate/EndDate (or ActionDateStart/ActionDateEnd) span wider than# 45 days; 44 keeps every window safely inside the inclusive limit.MAX_WINDOW_DAYS = 44diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/source.pyindex d33dd837a1e9..428a7e876746 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/source.py@@ -24,9 +24,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.impact.impvalidate_credentials as validate_impact_credentials,)from products.warehouse_sources.backend.temporal.data_imports.sources.impact.settings import (+ DEFAULT_API_VERSION,ENDPOINTS,IMPACT_ENDPOINTS,INCREMENTAL_FIELDS,+ SUPPORTED_API_VERSIONS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -36,6 +38,9 @@ class ImpactSource(ResumableSource[ImpactSourceConfig, ImpactResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docsapi_docs_url = "https://integrations.impact.com/brand-api-reference/readme/introduction"+ supported_versions = SUPPORTED_API_VERSIONS+ default_version = DEFAULT_API_VERSION+@propertydef source_type(self) -> ExternalDataSourceType:return ExternalDataSourceType.IMPACT@@ -122,7 +127,7 @@ Find these in impact.com under **Settings > Technical > API**. Create a Read-Onlschema_name: Optional[str] = None,api_version: str | None = None,) -> tuple[bool, str | None]:- if validate_impact_credentials(config.account_sid, config.auth_token):+ if validate_impact_credentials(config.account_sid, config.auth_token, self.resolve_api_version(api_version)):return True, Nonereturn False, "Invalid Impact.com Account SID or Auth Token"@@ -146,4 +151,5 @@ Find these in impact.com under **Settings > Technical > API**. Create a Read-Onldb_incremental_field_last_value=inputs.db_incremental_field_last_valueif inputs.should_use_incremental_fieldelse None,+ api_version=self.resolve_api_version(inputs.api_version),)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact.py b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact.pyindex daa8c8721d86..7bc5e3c5721e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact.py@@ -22,7 +22,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.impact.impimpact_source,validate_credentials,)-from products.warehouse_sources.backend.temporal.data_imports.sources.impact.settings import IMPACT_ENDPOINTS+from products.warehouse_sources.backend.temporal.data_imports.sources.impact.settings import (+ IMPACT_API_VERSION_14,+ IMPACT_API_VERSION_LEGACY,+ IMPACT_ENDPOINTS,+ IMPACT_VERSION_HEADER,+)class FakeResumableManager:@@ -198,6 +203,55 @@ class TestResumeIndex:assert _resume_index(work_items, resume) == 0+class TestApiVersionHeader:+ def _session_headers(self, api_version: str) -> dict[str, str]:+ with patch.object(impact, "make_tracked_session") as mock_session:+ session = MagicMock()+ session.headers = {}+ mock_session.return_value = session+ impact._get_session("sid", "token", api_version)+ return session.headers++ def test_legacy_version_sends_no_version_header(self) -> None:+ headers = self._session_headers(IMPACT_API_VERSION_LEGACY)+ assert IMPACT_VERSION_HEADER not in headers++ def test_dated_version_sends_version_header(self) -> None:+ headers = self._session_headers(IMPACT_API_VERSION_14)+ assert headers[IMPACT_VERSION_HEADER] == "14"++ @parameterized.expand([(IMPACT_API_VERSION_LEGACY, False), (IMPACT_API_VERSION_14, True)])+ def test_get_rows_threads_version_to_session(self, api_version: str, expects_header: bool) -> None:+ manager = FakeResumableManager()+ with (+ patch.object(impact, "make_tracked_session") as mock_session,+ patch.object(impact, "_fetch", return_value={"Campaigns": [], "@numpages": "1"}),+ ):+ session = MagicMock()+ session.headers = {}+ mock_session.return_value = session+ list(+ get_rows(+ "sid",+ "token",+ "Campaigns",+ MagicMock(),+ manager, # type: ignore[arg-type]+ api_version=api_version,+ )+ )+ assert (session.headers.get(IMPACT_VERSION_HEADER) == api_version) is expects_header++ def test_validate_credentials_threads_version_to_session(self) -> None:+ with patch.object(impact, "make_tracked_session") as mock_session:+ session = MagicMock()+ session.headers = {}+ session.get.return_value = MagicMock(status_code=200)+ mock_session.return_value = session+ validate_credentials("sid", "token", IMPACT_API_VERSION_14)+ assert session.headers[IMPACT_VERSION_HEADER] == "14"++class TestValidateCredentials:@parameterized.expand([("ok", 200, True), ("unauthorized", 401, False), ("forbidden", 403, False)])def test_status_maps_to_bool(self, _name: str, status: int, expected: bool) -> None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact_source.pyindex e8fa9fa3bb97..518fa2829ee3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/impact/tests/test_impact_source.py@@ -19,6 +19,7 @@ def _inputs(schema_name: str = "Actions", **overrides: object) -> MagicMock:inputs.schema_name = schema_nameinputs.should_use_incremental_field = overrides.get("should_use_incremental_field", True)inputs.db_incremental_field_last_value = overrides.get("db_incremental_field_last_value", "2024-01-01T00:00:00")+ inputs.api_version = overrides.get("api_version", None)return inputs@@ -148,3 +149,35 @@ class TestImpactSourceClass:ImpactSource().source_for_pipeline(ImpactSourceConfig(account_sid="s", auth_token="t"), manager, inputs)assert mock_impact_source.call_args.kwargs["db_incremental_field_last_value"] is None++ def test_default_version_is_14(self) -> None:+ assert ImpactSource.default_version == "14"+ assert ImpactSource.supported_versions == ("v1", "14")++ @parameterized.expand(+ [+ ("unpinned_resolves_to_default", None, "14"),+ ("legacy_pin_honored", "v1", "v1"),+ ("dated_pin_honored", "14", "14"),+ ]+ )+ def test_source_for_pipeline_passes_resolved_version(self, _name: str, pin: Optional[str], expected: str) -> None:+ manager = MagicMock()+ inputs = _inputs(schema_name="Actions", api_version=pin)+ with patch.object(source_module, "impact_source") as mock_impact_source:+ ImpactSource().source_for_pipeline(ImpactSourceConfig(account_sid="s", auth_token="t"), manager, inputs)++ assert mock_impact_source.call_args.kwargs["api_version"] == expected++ @parameterized.expand(+ [+ ("unpinned_resolves_to_default", None, "14"),+ ("legacy_pin_honored", "v1", "v1"),+ ]+ )+ def test_validate_credentials_passes_resolved_version(self, _name: str, pin: Optional[str], expected: str) -> None:+ with patch.object(source_module, "validate_impact_credentials", return_value=True) as mock_validate:+ ImpactSource().validate_credentials(+ ImpactSourceConfig(account_sid="s", auth_token="t"), team_id=1, api_version=pin+ )+ assert mock_validate.call_args.args[2] == expected