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.

feat(warehouse_sources): support Teamtailor API version 20240904 (#74153)

Tom Owersaa1a01688483
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/source.py
index 40de90f3fd41..47c1e822bf5f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/source.py
@@ -32,6 +32,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor
TEAMTAILOR_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.teamtailor import (
+ DEFAULT_API_VERSION,
+ SUPPORTED_API_VERSIONS,
TeamtailorResumeConfig,
teamtailor_source,
validate_credentials as _validate_credentials,
@@ -41,8 +43,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class TeamtailorSource(ResumableSource[TeamtailorSourceConfig, TeamtailorResumeConfig]):
- supported_versions = ("20240404",)
- default_version = "20240404"
+ supported_versions = SUPPORTED_API_VERSIONS
+ default_version = DEFAULT_API_VERSION
api_docs_url = "https://docs.teamtailor.com"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@@ -113,8 +115,10 @@ You can create an API key under **Settings → API keys** in Teamtailor. The key
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
- # The API key is account-wide, so a single probe validates access to every schema.
- return _validate_credentials(config.api_key)
+ # The API key is account-wide, so a single probe validates access to every schema. Pre-creation
+ # calls pass no pin and resolve to default_version (what new rows are stamped with); a pinned
+ # source revalidates under its own `X-Api-Version` header.
+ return _validate_credentials(config.api_key, self.resolve_api_version(api_version))
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[TeamtailorResumeConfig]:
return ResumableSourceManager[TeamtailorResumeConfig](inputs, TeamtailorResumeConfig)
@@ -134,5 +138,6 @@ You can create an API key under **Settings → API keys** in Teamtailor. The key
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
+ api_version=self.resolve_api_version(inputs.api_version),
db_incremental_field_last_value=None, # every Teamtailor endpoint is full refresh
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/teamtailor.py b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/teamtailor.py
index 5b3606bfbdd2..796da6d38a9d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/teamtailor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/teamtailor.py
@@ -16,8 +16,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor
TEAMTAILOR_BASE_URL = "https://api.teamtailor.com/v1"
# JSON:API caps `page[size]` at 30; the largest page minimises round trips.
PAGE_SIZE = 30
-# Every request must pin an API version; this dated value is a documented, stable release.
-API_VERSION = "20240404"
+# Every request must pin an API version via the `X-Api-Version` header — opaque dated labels, never
+# parsed or ordered. Teamtailor only cuts a new dated version for backwards-incompatible changes, so
+# for the top-level list endpoints we read (auto-inferred schema) the versions differ only in this
+# header value; the resolved pin is threaded down from the source class.
+API_VERSION_20240404 = "20240404"
+API_VERSION_20240904 = "20240904"
+SUPPORTED_API_VERSIONS = (API_VERSION_20240404, API_VERSION_20240904)
+DEFAULT_API_VERSION = API_VERSION_20240904
# Cheap endpoint used to confirm an API key is genuine. The key is account-wide, so one probe
# validates access to every list endpoint.
DEFAULT_PROBE_PATH = "/users"
@@ -31,18 +37,18 @@ class TeamtailorResumeConfig:
next_url: Optional[str] = None
-def _headers(api_key: str) -> dict[str, str]:
+def _headers(api_key: str, api_version: str) -> dict[str, str]:
return {
"Authorization": f"Token token={api_key}",
- "X-Api-Version": API_VERSION,
+ "X-Api-Version": api_version,
"Accept": "application/vnd.api+json",
}
-def _version_headers() -> dict[str, str]:
+def _version_headers(api_version: str) -> dict[str, str]:
# Auth (the `Token token=` header) is supplied via the framework auth config so its value is
# redacted from logs and errors; only the non-secret version/accept headers are set here.
- return {"X-Api-Version": API_VERSION, "Accept": "application/vnd.api+json"}
+ return {"X-Api-Version": api_version, "Accept": "application/vnd.api+json"}
def teamtailor_source(
@@ -51,6 +57,7 @@ def teamtailor_source(
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[TeamtailorResumeConfig],
+ api_version: str,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = TEAMTAILOR_ENDPOINTS[endpoint]
@@ -58,7 +65,7 @@ def teamtailor_source(
rest_config: RESTAPIConfig = {
"client": {
"base_url": TEAMTAILOR_BASE_URL,
- "headers": _version_headers(),
+ "headers": _version_headers(api_version),
# Teamtailor's scheme is `Authorization: Token token=<key>`; carry the whole credential
# string via api_key auth so the key is scrubbed from error messages and logged URLs.
"auth": {
@@ -120,13 +127,13 @@ def teamtailor_source(
)
-def check_access(api_key: str, path: str = DEFAULT_PROBE_PATH) -> tuple[int, Optional[str]]:
+def check_access(api_key: str, api_version: str, path: str = DEFAULT_PROBE_PATH) -> tuple[int, Optional[str]]:
"""Probe a single endpoint to validate the API key.
Returns ``(status, message)``: ``200`` reachable, ``401``/``403`` auth failure, ``0`` for a
connection problem, other HTTP status otherwise.
"""
- session = make_tracked_session(headers=_headers(api_key), redact_values=(api_key,))
+ session = make_tracked_session(headers=_headers(api_key, api_version), redact_values=(api_key,))
try:
response = session.get(f"{TEAMTAILOR_BASE_URL}{path}", params={"page[size]": 1}, timeout=15)
except Exception as e:
@@ -141,8 +148,8 @@ def check_access(api_key: str, path: str = DEFAULT_PROBE_PATH) -> tuple[int, Opt
return 200, None
-def validate_credentials(api_key: str) -> tuple[bool, str | None]:
- status, message = check_access(api_key)
+def validate_credentials(api_key: str, api_version: str) -> tuple[bool, str | None]:
+ status, message = check_access(api_key, api_version)
if status == 200:
return True, None
if status in (401, 403):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor.py b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor.py
index dbebf227a5a6..d62ed617f79d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor.py
@@ -20,8 +20,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor
TEAMTAILOR_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.teamtailor import (
- API_VERSION,
+ API_VERSION_20240404,
+ API_VERSION_20240904,
+ DEFAULT_API_VERSION,
PAGE_SIZE,
+ SUPPORTED_API_VERSIONS,
TeamtailorResumeConfig,
check_access,
teamtailor_source,
@@ -74,8 +77,10 @@ def _wire(mock_make_session: MagicMock, responses: list[Any]) -> tuple[requests.
return session, sent
-def _rows(endpoint: str, manager: MagicMock) -> list[dict[str, Any]]:
- response = teamtailor_source("tt-key", endpoint, team_id=1, job_id="j", resumable_source_manager=manager)
+def _rows(endpoint: str, manager: MagicMock, api_version: str = DEFAULT_API_VERSION) -> list[dict[str, Any]]:
+ response = teamtailor_source(
+ "tt-key", endpoint, team_id=1, job_id="j", resumable_source_manager=manager, api_version=api_version
+ )
return [row for page in cast("Iterable[Any]", response.items()) for row in page]
@@ -175,20 +180,25 @@ class TestErrorHandling:
class TestAuthHeaders:
- def test_headers_carry_token_and_api_version(self) -> None:
- headers = teamtailor._headers("tt-key")
+ @parameterized.expand([(v,) for v in SUPPORTED_API_VERSIONS])
+ def test_headers_carry_token_and_requested_api_version(self, api_version: str) -> None:
+ headers = teamtailor._headers("tt-key", api_version)
assert headers["Authorization"] == "Token token=tt-key"
- assert headers["X-Api-Version"] == API_VERSION
+ assert headers["X-Api-Version"] == api_version
assert headers["Accept"] == "application/vnd.api+json"
- def test_version_headers_carry_no_secret(self) -> None:
+ @parameterized.expand([(v,) for v in SUPPORTED_API_VERSIONS])
+ def test_version_headers_carry_no_secret(self, api_version: str) -> None:
# The API key travels via the framework auth config, not these static headers.
- headers = teamtailor._version_headers()
+ headers = teamtailor._version_headers(api_version)
assert "Authorization" not in headers
- assert headers["X-Api-Version"] == API_VERSION
+ assert headers["X-Api-Version"] == api_version
+ @parameterized.expand([("legacy", API_VERSION_20240404), ("current", API_VERSION_20240904)])
@patch(CLIENT_SESSION_PATCH)
- def test_token_auth_header_is_sent(self, mock_make_session: MagicMock) -> None:
+ def test_requested_api_version_reaches_the_wire(
+ self, _name: str, api_version: str, mock_make_session: MagicMock
+ ) -> None:
session, _ = _wire(mock_make_session, [_page([{"id": "1"}], next_url=None)])
captured: dict[str, str] = {}
@@ -200,10 +210,10 @@ class TestAuthHeaders:
return prepared
cast(Any, session).prepare_request = mock.MagicMock(side_effect=_prepare)
- _rows("candidates", _make_manager())
+ _rows("candidates", _make_manager(), api_version=api_version)
assert captured["Authorization"] == "Token token=tt-key"
- assert captured["X-Api-Version"] == API_VERSION
+ assert captured["X-Api-Version"] == api_version
class TestCheckAccess:
@@ -238,12 +248,12 @@ class TestCheckAccess:
response.status_code = status
response.ok = ok
self._configure_session(mock_make_session, response)
- assert check_access("tt-key") == (expected_status, expected_message)
+ assert check_access("tt-key", DEFAULT_API_VERSION) == (expected_status, expected_message)
@mock.patch.object(teamtailor, "make_tracked_session")
def test_connection_error_maps_to_zero(self, mock_make_session: MagicMock) -> None:
self._configure_session(mock_make_session, requests.ConnectionError("boom"))
- status, message = check_access("tt-key")
+ status, message = check_access("tt-key", DEFAULT_API_VERSION)
assert status == 0
assert message is not None and "boom" in message
@@ -268,14 +278,19 @@ class TestCheckAccess:
response.status_code = status
response.ok = status < 400
self._configure_session(mock_make_session, response)
- assert validate_credentials("tt-key") == (expected_valid, expected_message)
+ assert validate_credentials("tt-key", DEFAULT_API_VERSION) == (expected_valid, expected_message)
class TestTeamtailorSourceResponse:
@parameterized.expand([(e,) for e in ENDPOINTS])
def test_source_response_shape(self, endpoint: str) -> None:
response = teamtailor_source(
- "tt-key", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager()
+ "tt-key",
+ endpoint,
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ api_version=DEFAULT_API_VERSION,
)
assert response.name == endpoint
assert response.primary_keys == ["id"]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor_source.py
index fb6c397302df..844e8553c39c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/teamtailor/tests/test_teamtailor_source.py
@@ -12,6 +12,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.settings import ENDPOINTS
from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.source import TeamtailorSource
from products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.teamtailor import (
+ API_VERSION_20240404,
+ API_VERSION_20240904,
TeamtailorResumeConfig,
)
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -132,10 +134,25 @@ class TestTeamtailorSource:
assert isinstance(manager, ResumableSourceManager)
assert manager._data_class is TeamtailorResumeConfig
+ def test_version_declarations_default_to_current(self) -> None:
+ # New sources start on the newest stable version; the legacy pin stays selectable.
+ assert self.source.supported_versions == (API_VERSION_20240404, API_VERSION_20240904)
+ assert self.source.default_version == API_VERSION_20240904
+
+ @parameterized.expand(
+ [
+ ("no_pin_uses_default", None, API_VERSION_20240904),
+ ("legacy_pin_honored", API_VERSION_20240404, API_VERSION_20240404),
+ ("current_pin_honored", API_VERSION_20240904, API_VERSION_20240904),
+ ]
+ )
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.teamtailor.source.teamtailor_source")
- def test_source_for_pipeline_plumbs_arguments(self, mock_source: mock.MagicMock) -> None:
+ def test_source_for_pipeline_threads_resolved_version(
+ self, _name: str, pin: str | None, expected_version: str, mock_source: mock.MagicMock
+ ) -> None:
inputs = mock.MagicMock()
inputs.schema_name = "candidates"
+ inputs.api_version = pin
manager = mock.MagicMock()
self.source.source_for_pipeline(self.config, manager, inputs)
@@ -145,6 +162,7 @@ class TestTeamtailorSource:
assert kwargs["api_key"] == "tt-key"
assert kwargs["endpoint"] == "candidates"
assert kwargs["resumable_source_manager"] is manager
+ assert kwargs["api_version"] == expected_version
def test_source_for_pipeline_rejects_unknown_schema(self) -> None:
inputs = mock.MagicMock()