: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 Factorial API version 2026-04-01 (#74162)
Tom Owers4dbbd2b9cf04
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.mdindex 9e91898783da..119630cde35b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md@@ -6,8 +6,12 @@ Source-local notes for the Factorial (HRIS) connector. See the official referenc## Connection- **Host:** single global host `https://api.factorialhr.com` (no per-account subdomains).-- **Version:** dated path segment, pinned to `2025-04-01` → base `https://api.factorialhr.com/api/2025-04-01`.- Resources occasionally move between groups across versions, so the version is pinned in `factorial.py`.+- **Version:** dated path segment → base `https://api.factorialhr.com/api/<version>`. Supported labels+ `2025-04-01` and `2026-04-01` (default); the source's resolved pin is threaded into the base URL in+ `factorial.py`. Resources occasionally move between groups across versions, but the resource paths and+ the `{"meta": ..., "data": [...]}` envelope our reads use are identical across both supported labels+ (`2026-04-01` only adds/removes response fields, which the auto-inferred schema absorbs). The id→string+ identifier migration lands in the later `2026-07-01` version, so ids stay integers on both.- **Auth:** `x-api-key: <key>` header (API key). OAuth2 is also supported by Factorial but not implementedhere — API key auth is fully supported for company/internal integrations and grants total account access.- **Resource path shape:** `/resources/<group>/<resource>` (e.g. `/resources/employees/employees`).diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/factorial.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/factorial.pyindex fd85d4fe7440..f97dc9db188c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/factorial.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/factorial.py@@ -14,12 +14,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.factorial.settings import FACTORIAL_ENDPOINTS-# Factorial uses a single global host (no per-account subdomains) and dated, version-pinned paths.-# `2025-04-01` is a stable release within the currently supported version range; pinning avoids-# silently picking up breaking changes (resources occasionally move between groups across versions).+# Factorial uses a single global host (no per-account subdomains) and dated API versions carried as a+# path segment. Each label is a stable release; newer versions add or drop response fields (which the+# auto-inferred schema turns into columns) but keep the `/resources/<group>/<resource>` paths and the+# `{"meta": ..., "data": [...]}` envelope our reads depend on. Ordered oldest → newest.FACTORIAL_HOST = "https://api.factorialhr.com"-API_VERSION = "2025-04-01"-BASE_URL = f"{FACTORIAL_HOST}/api/{API_VERSION}"+API_VERSION_2025_04_01 = "2025-04-01"+API_VERSION_2026_04_01 = "2026-04-01"+++def base_url(api_version: str) -> str:+ return f"{FACTORIAL_HOST}/api/{api_version}"+# Factorial caps `limit` at 100 records per page across list endpoints (the default is also 100).PAGE_SIZE = 100@@ -109,12 +115,13 @@ def factorial_source(team_id: int,job_id: str,resumable_source_manager: ResumableSourceManager[FactorialResumeConfig],+ api_version: str,) -> SourceResponse:endpoint_config = FACTORIAL_ENDPOINTS[endpoint]rest_config: RESTAPIConfig = {"client": {- "base_url": BASE_URL,+ "base_url": base_url(api_version),# Factorial authenticates with the account-wide `x-api-key` header. Going through# APIKeyAuth (rather than raw headers) registers the key for value-based log redaction."auth": {@@ -170,11 +177,11 @@ def factorial_source()-def validate_credentials(api_key: str) -> tuple[bool, str | None]:+def validate_credentials(api_key: str, api_version: str) -> tuple[bool, str | None]:# Probe the core Employees resource: every HRIS account has it, and an API key with no access# would 401/403 here. Factorial API keys carry total account access, so there is no per-scope# nuance to accept at source-create time the way OAuth-scoped sources need.- url = f"{BASE_URL}/resources/employees/employees"+ url = f"{base_url(api_version)}/resources/employees/employees"try:response = make_tracked_session(redact_values=(api_key,)).get(url,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.pyindex f1ab95f9fc25..eaa7dabdd4b4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py@@ -21,6 +21,8 @@ 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.factorial.factorial import (+ API_VERSION_2025_04_01,+ API_VERSION_2026_04_01,FactorialResumeConfig,factorial_source,validate_credentials as validate_factorial_credentials,@@ -39,8 +41,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass FactorialSource(ResumableSource[FactorialSourceConfig, FactorialResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docs- supported_versions = ("2025-04-01",)- default_version = "2025-04-01"+ supported_versions = (API_VERSION_2025_04_01, API_VERSION_2026_04_01)+ default_version = API_VERSION_2026_04_01api_docs_url = "https://apidoc.factorialhr.com/docs/api-versioning"@property@@ -124,7 +126,7 @@ Create an API key in your Factorial account under **Settings > API keys** (or **schema_name: Optional[str] = None,api_version: str | None = None,) -> tuple[bool, str | None]:- return validate_factorial_credentials(config.api_key)+ return validate_factorial_credentials(config.api_key, self.resolve_api_version(api_version))def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[FactorialResumeConfig]:return ResumableSourceManager[FactorialResumeConfig](inputs, FactorialResumeConfig)@@ -141,4 +143,5 @@ Create an API key in your Factorial account under **Settings > API keys** (or **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),)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial.pyindex dda2863f7d67..0ab00f60cd96 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial.py@@ -9,10 +9,12 @@ from requests import Request, Responsefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.factorial.factorial import (- BASE_URL,+ API_VERSION_2025_04_01,+ API_VERSION_2026_04_01,PAGE_SIZE,FactorialCursorPaginator,FactorialResumeConfig,+ base_url,factorial_source,get_resource,validate_credentials,@@ -26,6 +28,9 @@ _SESSION_FACTORY = ("products.warehouse_sources.backend.temporal.data_imports.sources.factorial.factorial.make_tracked_session")+# Paginator logic ignores the request URL (it only touches params), so any supported base is fine here.+_BASE_URL = base_url(API_VERSION_2026_04_01)+def _full_page() -> list[dict[str, Any]]:return [{"id": i} for i in range(PAGE_SIZE)]@@ -44,7 +49,7 @@ class TestFactorialCursorPaginator:def test_init_request_emits_limit_only_when_fresh(self) -> None:paginator = FactorialCursorPaginator()- request = Request(method="GET", url=f"{BASE_URL}/resources/employees/employees")+ request = Request(method="GET", url=f"{_BASE_URL}/resources/employees/employees")paginator.init_request(request)assert request.params["limit"] == PAGE_SIZEassert "after_id" not in request.params@@ -54,7 +59,7 @@ class TestFactorialCursorPaginator:paginator.update_state(_meta_response({"has_next_page": True, "end_cursor": "Mjc="}), _full_page())assert paginator.has_next_page is True- request = Request(method="GET", url=f"{BASE_URL}/resources/employees/employees")+ request = Request(method="GET", url=f"{_BASE_URL}/resources/employees/employees")paginator.update_request(request)assert request.params["after_id"] == "Mjc="@@ -89,7 +94,7 @@ class TestFactorialCursorPaginator:paginator.set_resume_state({"after_id": "MTY="})assert paginator.has_next_page is True- request = Request(method="GET", url=f"{BASE_URL}/resources/employees/employees")+ request = Request(method="GET", url=f"{_BASE_URL}/resources/employees/employees")paginator.init_request(request)assert request.params["after_id"] == "MTY="assert request.params["limit"] == PAGE_SIZE@@ -97,7 +102,7 @@ class TestFactorialCursorPaginator:def test_set_resume_state_ignores_missing_cursor(self) -> None:paginator = FactorialCursorPaginator()paginator.set_resume_state({})- request = Request(method="GET", url=f"{BASE_URL}/resources/employees/employees")+ request = Request(method="GET", url=f"{_BASE_URL}/resources/employees/employees")paginator.init_request(request)assert "after_id" not in request.params@@ -131,6 +136,7 @@ class TestSourceResponsePartitioning:team_id=123,job_id="job-1",resumable_source_manager=manager,+ api_version=API_VERSION_2026_04_01,)@pytest.mark.parametrize(@@ -172,13 +178,19 @@ class TestFactorialSourceResumeBehavior:"""End-to-end resume behaviour of ``factorial_source`` via ``rest_api_resource``."""def _drive(- self, endpoint: str, manager: MagicMock, responses: list[Response]- ) -> tuple[MagicMock, list[dict[str, Any]]]:+ self,+ endpoint: str,+ manager: MagicMock,+ responses: list[Response],+ api_version: str = API_VERSION_2026_04_01,+ ) -> tuple[list[dict[str, Any]], list[str]]:sent_params: list[dict[str, Any]] = []+ sent_urls: list[str] = []response_iter = iter(responses)def fake_send(request: Any, *_args: Any, **_kwargs: Any) -> Response:sent_params.append(dict(request.params or {}))+ sent_urls.append(request.url)return next(response_iter)with patch(_SESSION_FACTORY) as MockSession:@@ -193,9 +205,10 @@ class TestFactorialSourceResumeBehavior:team_id=123,job_id="test_job",resumable_source_manager=manager,+ api_version=api_version,)list(cast(Iterable[Any], source.items()))- return mock_session, sent_params+ return sent_params, sent_urlsdef _page_body(self, items: list[dict[str, Any]], meta: dict[str, Any]) -> dict[str, Any]:return {"data": items, "meta": meta}@@ -208,7 +221,7 @@ class TestFactorialSourceResumeBehavior:_make_http_response(self._page_body(_full_page(), {"has_next_page": True, "end_cursor": "Mjc="})),_make_http_response(self._page_body([{"id": 999}], {"has_next_page": False, "end_cursor": None})),]- _, sent_params = self._drive("employees", manager, responses)+ sent_params, _ = self._drive("employees", manager, responses)# First request starts without a cursor; the second carries the advanced after_id.assert "after_id" not in sent_params[0]@@ -226,11 +239,24 @@ class TestFactorialSourceResumeBehavior:responses = [_make_http_response(self._page_body([{"id": 17}], {"has_next_page": False, "end_cursor": None})),]- _, sent_params = self._drive("employees", manager, responses)+ sent_params, _ = self._drive("employees", manager, responses)assert sent_params[0].get("after_id") == "MTY="manager.load_state.assert_called_once()+ @pytest.mark.parametrize("api_version", [API_VERSION_2025_04_01, API_VERSION_2026_04_01])+ def test_requests_go_to_the_pinned_version_path(self, api_version: str) -> None:+ # A pinned source must fetch under its own version segment — never a hardcoded default.+ manager = MagicMock(spec=ResumableSourceManager)+ manager.can_resume.return_value = False+ responses = [+ _make_http_response(self._page_body([{"id": 1}], {"has_next_page": False, "end_cursor": None})),+ ]+ _, sent_urls = self._drive("employees", manager, responses, api_version=api_version)++ assert sent_urls+ assert all(url.startswith(f"{base_url(api_version)}/resources/employees/employees") for url in sent_urls)+def test_terminal_single_page_does_not_save_state(self) -> None:manager = MagicMock(spec=ResumableSourceManager)manager.can_resume.return_value = False@@ -271,24 +297,25 @@ class TestValidateCredentials:response.status_code = status_codemock_session.get.return_value = response- valid, error = validate_credentials("test-key")+ valid, error = validate_credentials("test-key", API_VERSION_2026_04_01)assert valid is expected_validif expected_valid:assert error is Noneelse:assert error is not None- def test_probes_employees_endpoint_with_api_key_header(self) -> None:+ @pytest.mark.parametrize("api_version", [API_VERSION_2025_04_01, API_VERSION_2026_04_01])+ def test_probes_employees_endpoint_under_requested_version(self, api_version: str) -> None:with patch(_SESSION_FACTORY) as MockSession:mock_session = MockSession.return_valueresponse = MagicMock()response.status_code = 200mock_session.get.return_value = response- validate_credentials("test-key")+ validate_credentials("test-key", api_version)call = mock_session.get.call_args- assert call.args[0] == f"{BASE_URL}/resources/employees/employees"+ assert call.args[0] == f"{base_url(api_version)}/resources/employees/employees"assert call.kwargs["headers"] == {"x-api-key": "test-key"}assert call.kwargs["params"] == {"limit": 1}assert call.kwargs["allow_redirects"] is False@@ -296,6 +323,6 @@ class TestValidateCredentials:def test_network_error_returns_message(self) -> None:with patch(_SESSION_FACTORY) as MockSession:MockSession.return_value.get.side_effect = Exception("boom")- valid, error = validate_credentials("test-key")+ valid, error = validate_credentials("test-key", API_VERSION_2026_04_01)assert valid is Falseassert error == "boom"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.pyindex e575f42cc2eb..07c5cac0c789 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py@@ -129,17 +129,29 @@ class TestFactorialSource:assert is_valid is expected_validassert error_message == expected_message- mock_validate.assert_called_once_with("test-key")+ # No row pin at creation time, so the probe runs under the default (newest) version.+ mock_validate.assert_called_once_with("test-key", "2026-04-01")def test_get_resumable_source_manager_bound_to_resume_config(self) -> None:manager = self.source.get_resumable_source_manager(_make_inputs())assert isinstance(manager, ResumableSourceManager)assert manager._data_class is FactorialResumeConfig+ @pytest.mark.parametrize(+ ("pin", "resolved"),+ [+ # None pin resolves to the default (the newest supported version) — new sources land here.+ (None, "2026-04-01"),+ ("2025-04-01", "2025-04-01"),+ ("2026-04-01", "2026-04-01"),+ ],+ )@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.factorial.source.factorial_source")- def test_source_for_pipeline_passes_arguments(self, mock_factorial_source: mock.MagicMock) -> None:+ def test_source_for_pipeline_resolves_and_threads_version(+ self, mock_factorial_source: mock.MagicMock, pin: str | None, resolved: str+ ) -> None:manager = mock.MagicMock(spec=ResumableSourceManager)- inputs = _make_inputs(schema_name="leaves", team_id=99, job_id="job-xyz")+ inputs = _make_inputs(schema_name="leaves", team_id=99, job_id="job-xyz", api_version=pin)self.source.source_for_pipeline(self.config, manager, inputs)@@ -149,4 +161,5 @@ class TestFactorialSource:team_id=99,job_id="job-xyz",resumable_source_manager=manager,+ api_version=resolved,)