Skip to content

: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.

fix(warehouse_sources): thread the resolved API version pin into legacy credential probes (#72979)

Daniel RCcd750e75a922
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
index e3061bcc7436..69cc9733e01e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
@@ -131,7 +131,7 @@ You can find your public and private keys in the [Braintree control panel](https
api_version: str | None = None,
) -> tuple[bool, str | None]:
if validate_braintree_credentials(
- config.environment, config.public_key, config.private_key, self.resolve_api_version(None)
+ config.environment, config.public_key, config.private_key, self.resolve_api_version(api_version)
):
return True, None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
index e42121cf7d5e..9a84a1d0033b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
@@ -3,7 +3,11 @@ from unittest import mock
from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType, SourceFieldSelectConfig
-from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.braintree import BraintreeResumeConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.braintree import (
+ BRAINTREE_VERSION_2019_01_01,
+ BRAINTREE_VERSION_2026_07_14,
+ BraintreeResumeConfig,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.settings import (
ENDPOINTS,
INCREMENTAL_FIELDS,
@@ -189,3 +193,25 @@ class TestBraintreeSource:
self.source.source_for_pipeline(self.config, mock.MagicMock(), inputs)
assert mock_bt_source.call_args.kwargs["api_version"] == expected
+
+
+class TestValidateCredentialsResolvedPin:
+ @pytest.mark.parametrize(
+ "pin, expected",
+ [
+ # The no-pin (None -> default) case is already covered by test_validate_credentials.
+ (BRAINTREE_VERSION_2019_01_01, BRAINTREE_VERSION_2019_01_01),
+ (BRAINTREE_VERSION_2026_07_14, BRAINTREE_VERSION_2026_07_14),
+ ],
+ )
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.braintree.source.validate_braintree_credentials"
+ )
+ def test_probe_receives_resolved_pin(self, mock_validate, pin, expected):
+ # A pinned source must revalidate under its own version, not always the default.
+ mock_validate.return_value = True
+ config = BraintreeSourceConfig(environment="production", public_key="pub", private_key="priv")
+
+ BraintreeSource().validate_credentials(config, 1, api_version=pin)
+
+ assert mock_validate.call_args.args[-1] == expected
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.py
index fc5b6d19a269..24ba5ccdef40 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
@@ -130,10 +130,12 @@ def _get_headers(api_key: str, revision: str = KLAVIYO_API_VERSION_2026_07_15) -
}
-def validate_credentials(api_key: str) -> bool:
+def validate_credentials(api_key: str, api_version: str = KLAVIYO_API_VERSION_2026_07_15) -> bool:
+ # Probe under the caller's resolved pin so a 2024-10-15-pinned source validates on the
+ # same `revision` header it syncs with.
url = f"{KLAVIYO_BASE_URL}/accounts"
try:
- response = make_tracked_session().get(url, headers=_get_headers(api_key), timeout=10)
+ response = make_tracked_session().get(url, headers=_get_headers(api_key, api_version), timeout=10)
return response.status_code == 200
except Exception:
return False
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.py
index a6aefb9d138f..5a3b010e1855 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
@@ -164,7 +164,7 @@ Make sure to grant the following read permissions:
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
- if validate_klaviyo_credentials(config.api_key):
+ if validate_klaviyo_credentials(config.api_key, self.resolve_api_version(api_version)):
return True, None
return False, "Invalid Klaviyo API key"
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.py
index 4e7f547bd522..14702b86acd9 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
@@ -8,7 +8,14 @@ from unittest.mock import MagicMock, patch
import requests
from parameterized import parameterized
+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.klaviyo import (
+ KlaviyoSourceConfig,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo import klaviyo
+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,
_build_filter,
@@ -536,3 +543,33 @@ class TestVersionDeprecation:
assert deprecation is not None
assert deprecation.sunset_at == date(2026, 10, 15)
assert source.get_version_deprecation("2026-07-15") is None
+
+
+class TestValidateCredentialsResolvedPin:
+ @parameterized.expand(
+ [
+ (KLAVIYO_API_VERSION_2024_10_15, KLAVIYO_API_VERSION_2024_10_15),
+ (KLAVIYO_API_VERSION_2026_07_15, KLAVIYO_API_VERSION_2026_07_15),
+ # No pin (pre-creation) resolves to the default the new row is stamped with.
+ (None, KLAVIYO_API_VERSION_2026_07_15),
+ ]
+ )
+ def test_class_probe_threads_resolved_pin(self, pin: str | None, expected: str) -> None:
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.klaviyo.source.validate_klaviyo_credentials",
+ return_value=True,
+ ) as mock_validate:
+ KlaviyoSource().validate_credentials(KlaviyoSourceConfig(api_key="pk_test"), 1, api_version=pin)
+
+ assert mock_validate.call_args.args[-1] == expected
+
+ @parameterized.expand([(KLAVIYO_API_VERSION_2024_10_15,), (KLAVIYO_API_VERSION_2026_07_15,)])
+ def test_probe_sends_pin_as_revision_header(self, api_version: str) -> None:
+ # A 2024-10-15-pinned source must validate on the same `revision` header it syncs with.
+ with patch.object(klaviyo, "make_tracked_session") as session_factory:
+ response = MagicMock(status_code=200)
+ session_factory.return_value.get.return_value = response
+ assert klaviyo.validate_credentials("pk_test", api_version) is True
+
+ headers = session_factory.return_value.get.call_args.kwargs["headers"]
+ assert headers["revision"] == api_version
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
index 4891d55e04c6..70d06c7f71a7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
@@ -120,9 +120,9 @@ Then **share** each page or database you want to sync with the integration (via
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
- # Runs at creation time with no row pin; new sources are stamped with default_version, and
- # the /v1/users/me probe is version-agnostic, so validate under the default.
- return validate_notion_credentials(config.api_key, self.default_version)
+ # Pre-creation calls pass no pin and resolve to default_version (what new rows are
+ # stamped with); a pinned source revalidates under its own `Notion-Version` header.
+ return validate_notion_credentials(config.api_key, self.resolve_api_version(api_version))
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[NotionResumeConfig]:
return ResumableSourceManager[NotionResumeConfig](inputs, NotionResumeConfig)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
index 12a3f5986c95..75a6024a71fb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
@@ -10,7 +10,11 @@ from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInp
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceInputs
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.notion import NotionSourceConfig
-from products.warehouse_sources.backend.temporal.data_imports.sources.notion.notion import NotionResumeConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.notion.notion import (
+ NOTION_VERSION_2025_09_03,
+ NOTION_VERSION_2026_03_11,
+ NotionResumeConfig,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.notion.settings import ENDPOINTS
from products.warehouse_sources.backend.temporal.data_imports.sources.notion.source import NotionSource
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -157,3 +161,24 @@ def test_http_error_message_format_matches_non_retryable(status_code: int) -> No
mock_response.raise_for_status()
non_retryable = NotionSource().get_non_retryable_errors()
assert not any(pattern in str(exc_info.value) for pattern in non_retryable)
+
+
+class TestValidateCredentialsResolvedPin:
+ @parameterized.expand(
+ [
+ (NOTION_VERSION_2025_09_03, NOTION_VERSION_2025_09_03),
+ (NOTION_VERSION_2026_03_11, NOTION_VERSION_2026_03_11),
+ # No pin (pre-creation) resolves to the default the new row is stamped with.
+ (None, NOTION_VERSION_2026_03_11),
+ ]
+ )
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.notion.source.validate_notion_credentials"
+ )
+ def test_probe_receives_resolved_pin(self, pin, expected, mock_validate: mock.Mock) -> None:
+ # The probe sends the `Notion-Version` header, so a pinned source must revalidate
+ # under its own version rather than always the default.
+ mock_validate.return_value = (True, None)
+ NotionSource().validate_credentials(NotionSourceConfig(api_key="secret_x"), 1, api_version=pin)
+
+ assert mock_validate.call_args.args[-1] == expected
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/servicenow.py b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/servicenow.py
index 48572101f495..5b8656850e14 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/servicenow.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/servicenow.py
@@ -168,6 +168,8 @@ def validate_credentials(
auth: ServiceNowAuth,
team_id: int,
table: Optional[str] = None,
+ *,
+ api_version: str,
) -> tuple[bool, str | None]:
try:
base_url = _resolve_base_url(instance_url, team_id)
@@ -176,8 +178,10 @@ def validate_credentials(
# Probe a cheap single-row read. At source-create (no specific table) we probe
# `sys_user`; otherwise probe the requested table to confirm scope for it.
+ # The probe hits the same versioned Table API path the sync uses, so a v1-pinned
+ # source validates against the path it actually reads from.
probe_table = table or "sys_user"
- url = f"{base_url}/api/now/table/{probe_table}"
+ url = _table_api_url(base_url, probe_table, api_version)
params: dict[str, Any] = {"sysparm_limit": 1, "sysparm_fields": "sys_id"}
try:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/source.py
index c3d555e5fd53..f0c768d631a0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/source.py
@@ -189,7 +189,9 @@ The account or API key needs **read** access (the `rest_api_explorer` role or eq
return False, str(exc)
table = SERVICENOW_ENDPOINTS[schema_name].table if schema_name in SERVICENOW_ENDPOINTS else None
- return validate_servicenow_credentials(config.instance_url, auth, team_id, table=table)
+ return validate_servicenow_credentials(
+ config.instance_url, auth, team_id, table=table, api_version=self.resolve_api_version(api_version)
+ )
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[ServiceNowResumeConfig]:
return ResumableSourceManager[ServiceNowResumeConfig](inputs, ServiceNowResumeConfig)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow.py b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow.py
index 839cb3c2e51d..6357ba558966 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow.py
@@ -192,28 +192,44 @@ class TestValidateCredentials:
get_mock = mock.Mock(return_value=FakeResponse(status_code=status))
with mock.patch.object(servicenow_module, "make_tracked_session", return_value=_patch_session(get_mock)):
valid, _ = validate_credentials(
- "https://acme.service-now.com", ServiceNowAuth(api_key="x"), team_id=1, table=table
+ "https://acme.service-now.com",
+ ServiceNowAuth(api_key="x"),
+ team_id=1,
+ table=table,
+ api_version=SERVICENOW_API_VERSION_V1,
)
assert valid is expected_valid
def test_redirect_is_rejected(self) -> None:
get_mock = mock.Mock(return_value=FakeResponse(status_code=302))
with mock.patch.object(servicenow_module, "make_tracked_session", return_value=_patch_session(get_mock)):
- valid, error = validate_credentials("https://acme.service-now.com", ServiceNowAuth(api_key="x"), team_id=1)
+ valid, error = validate_credentials(
+ "https://acme.service-now.com",
+ ServiceNowAuth(api_key="x"),
+ team_id=1,
+ api_version=SERVICENOW_API_VERSION_V1,
+ )
assert valid is False
assert error is not None
# redirects must not be followed (SSRF guard)
assert get_mock.call_args.kwargs["allow_redirects"] is False
def test_invalid_instance_url(self) -> None:
- valid, error = validate_credentials("", ServiceNowAuth(api_key="x"), team_id=1)
+ valid, error = validate_credentials(
+ "", ServiceNowAuth(api_key="x"), team_id=1, api_version=SERVICENOW_API_VERSION_V1
+ )
assert valid is False
assert error is not None
def test_network_error_is_handled(self) -> None:
get_mock = mock.Mock(side_effect=requests.ConnectionError("boom"))
with mock.patch.object(servicenow_module, "make_tracked_session", return_value=_patch_session(get_mock)):
- valid, error = validate_credentials("https://acme.service-now.com", ServiceNowAuth(api_key="x"), team_id=1)
+ valid, error = validate_credentials(
+ "https://acme.service-now.com",
+ ServiceNowAuth(api_key="x"),
+ team_id=1,
+ api_version=SERVICENOW_API_VERSION_V1,
+ )
assert valid is False
assert error is not None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow_source.py
index 570affea3f09..4b5e9c7d26a7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/servicenow/tests/test_servicenow_source.py
@@ -12,6 +12,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
ServiceNowSourceConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.servicenow.servicenow import (
+ SERVICENOW_API_VERSION_V1,
+ SERVICENOW_API_VERSION_V2,
ServiceNowAuth,
ServiceNowResumeConfig,
)
@@ -208,3 +210,25 @@ class TestServiceNowSource:
_, kwargs = mock_source.call_args
assert kwargs["api_version"] == expected
+
+
+class TestValidateCredentialsResolvedPin:
+ @parameterized.expand(
+ [
+ (SERVICENOW_API_VERSION_V1, SERVICENOW_API_VERSION_V1),
+ (SERVICENOW_API_VERSION_V2, SERVICENOW_API_VERSION_V2),
+ # No pin (pre-creation) resolves to the default the new row is stamped with.
+ (None, ServiceNowSource.default_version),
+ ]
+ )
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.servicenow.source.validate_servicenow_credentials"
+ )
+ def test_probe_receives_resolved_pin(self, pin, expected, mock_validate: mock.Mock) -> None:
+ # The probe hits the versioned Table API path, so a v1-pinned source must validate
+ # against /api/now/table while the (v2) default validates against /api/now/v2/table.
+ mock_validate.return_value = (True, None)
+ ServiceNowSource().validate_credentials(_api_key_config(), 1, api_version=pin)
+
+ _, kwargs = mock_validate.call_args
+ assert kwargs["api_version"] == expected