: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 Inngest API version v2 (#74171)
Tom Owersb750dfd95ec7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/inngest.py b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/inngest.pyindex 0032db33deda..90f33c7c2c83 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/inngest.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/inngest.py@@ -12,6 +12,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelinefrom 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 ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.inngest.settings import (+ INNGEST_DEFAULT_VERSION,INNGEST_ENDPOINTS,InngestEndpointConfig,)@@ -312,6 +313,7 @@ def _get_v2_list_rows(headers: dict[str, str],logger: FilteringBoundLogger,config: InngestEndpointConfig,+ path: str,) -> Iterator[list[dict[str, Any]]]:"""Page a v2 list endpoint via its `page.cursor` / `page.hasMore` envelope.@@ -321,7 +323,7 @@ def _get_v2_list_rows(cursor: str | None = Nonewhile True:params = {"cursor": cursor} if cursor else None- payload = _fetch(session, f"{INNGEST_API_BASE_URL}{config.path}", headers, logger, params=params)+ payload = _fetch(session, f"{INNGEST_API_BASE_URL}{path}", headers, logger, params=params)items = payload.get("data") or []rows = [_drop_redacted_fields(item, config.redacted_fields) for item in items if isinstance(item, dict)]if rows:@@ -339,8 +341,9 @@ def _get_v1_list_rows(headers: dict[str, str],logger: FilteringBoundLogger,config: InngestEndpointConfig,+ path: str,) -> Iterator[list[dict[str, Any]]]:- payload = _fetch(session, f"{INNGEST_API_BASE_URL}{config.path}", headers, logger)+ payload = _fetch(session, f"{INNGEST_API_BASE_URL}{path}", headers, logger)data = payload.get("data") if isinstance(payload, dict) else payload# The v1 spec is ambiguous about whether these small lists come back as an array or a single# object; handle both.@@ -359,8 +362,14 @@ def get_rows(resumable_source_manager: ResumableSourceManager[InngestResumeConfig],should_use_incremental_field: bool = False,db_incremental_field_last_value: Any = None,+ api_version: str = INNGEST_DEFAULT_VERSION,) -> Iterator[list[dict[str, Any]]]:config = INNGEST_ENDPOINTS[endpoint]+ # Version-mobile resources (webhooks) select their path + pagination from the source's pin;+ # version-locked ones fall through to the single `path`/`pagination` on the config.+ variant = config.version_paths.get(api_version)+ path = variant.path if variant else config.path+ pagination = variant.pagination if variant else config.paginationheaders = _get_headers(signing_key, environment)# One session reused across every page (and every per-event runs request) so urllib3 keeps the# connection alive. Register the signing key for value-based redaction and disable sample@@ -377,7 +386,7 @@ def get_rows(should_use_incremental_field,db_incremental_field_last_value,)- elif config.pagination == "events_cursor":+ elif pagination == "events_cursor":yield from _get_event_rows(session,headers,@@ -386,10 +395,10 @@ def get_rows(should_use_incremental_field,db_incremental_field_last_value,)- elif config.pagination == "v2_cursor":- yield from _get_v2_list_rows(session, headers, logger, config)+ elif pagination == "v2_cursor":+ yield from _get_v2_list_rows(session, headers, logger, config, path)else:- yield from _get_v1_list_rows(session, headers, logger, config)+ yield from _get_v1_list_rows(session, headers, logger, config, path)def inngest_source(@@ -400,6 +409,7 @@ def inngest_source(resumable_source_manager: ResumableSourceManager[InngestResumeConfig],should_use_incremental_field: bool = False,db_incremental_field_last_value: Optional[Any] = None,+ api_version: str = INNGEST_DEFAULT_VERSION,) -> SourceResponse:config = INNGEST_ENDPOINTS[endpoint]@@ -413,6 +423,7 @@ def inngest_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,# The events walk's ordering within the window is undocumented (and could not bediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/settings.pyindex cb0aa8f3d706..6a158f038905 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/settings.py@@ -3,6 +3,23 @@ from typing import Literal, Optionalfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType+# Vendor API versions. Inngest serves its REST API under URL-path-versioned prefixes+# (`/v1/...`, `/v2/...`) and the per-environment signing key authenticates both. Most resources+# live under a single version — the events walk and cancellations are v1-only, while environments+# and the key inventories are v2-only — so their paths are fixed regardless of a source's pin.+# Webhooks is served under both, so a source's pin selects which inventory it reads (see+# `version_paths` below). New sources default to v2.+INNGEST_API_VERSION_V1 = "v1"+INNGEST_API_VERSION_V2 = "v2"+INNGEST_SUPPORTED_VERSIONS = (INNGEST_API_VERSION_V1, INNGEST_API_VERSION_V2)+INNGEST_DEFAULT_VERSION = INNGEST_API_VERSION_V2+++@dataclass(frozen=True)+class InngestVersionPath:+ path: str+ pagination: Literal["events_cursor", "v2_cursor", "none"]+@dataclassclass InngestEndpointConfig:@@ -28,6 +45,10 @@ class InngestEndpointConfig:# Per-schema default overlap window re-read on each incremental run (see SourceSchema).default_incremental_lookback_seconds: Optional[int] = Noneshould_sync_default: bool = True+ # For resources Inngest serves under more than one API version, the path + pagination the+ # source uses per resolved `api_version` pin. Absent → the resource is version-locked to+ # `path` (its only compatible home) and every pin reads it there.+ version_paths: dict[str, InngestVersionPath] = field(default_factory=dict)# Endpoint catalog. Inngest's REST API lives at api.inngest.com (v1 + v2), authenticated with a@@ -103,6 +124,14 @@ INNGEST_ENDPOINTS: dict[str, InngestEndpointConfig] = {primary_keys=["id"],pagination="none",redacted_fields=("url",),+ # Webhooks is the one resource this source reads that Inngest serves under both versions.+ # A v2-pinned source reads the v2 inventory (cursor envelope) to stay consistent with its+ # other v2-native reads; v1 pins keep the original `/v1/webhooks` list path. The v2+ # envelope could not be curl-verified without credentials, but `_get_v2_list_rows`+ # degrades to a single page when the response carries no `page` object.+ version_paths={+ INNGEST_API_VERSION_V2: InngestVersionPath(path="/v2/webhooks", pagination="v2_cursor"),+ },),"event_keys": InngestEndpointConfig(name="event_keys",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/source.pyindex e059406dbc30..552c87be7707 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/source.py@@ -31,7 +31,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.inngest.infrom products.warehouse_sources.backend.temporal.data_imports.sources.inngest.settings import (ENDPOINTS,INCREMENTAL_FIELDS,+ INNGEST_DEFAULT_VERSION,INNGEST_ENDPOINTS,+ INNGEST_SUPPORTED_VERSIONS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -40,6 +42,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceTypeclass InngestSource(ResumableSource[InngestSourceConfig, InngestResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docsapi_docs_url = "https://api-docs.inngest.com"+ supported_versions = INNGEST_SUPPORTED_VERSIONS+ default_version = INNGEST_DEFAULT_VERSION@propertydef source_type(self) -> ExternalDataSourceType:@@ -175,4 +179,5 @@ Inngest retains event and run history for a plan-dependent window (from 24 hoursdb_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/inngest/tests/test_inngest.py b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest.pyindex bf9c314af72d..e95f1af7e53b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest.py@@ -42,6 +42,7 @@ def _run_rows(endpoint: str,fake_fetch: Any,manager: _FakeResumableManager | None = None,+ api_version: str = "v1",**incremental: Any,) -> tuple[list[dict], _FakeResumableManager]:manager = manager or _FakeResumableManager()@@ -53,6 +54,7 @@ def _run_rows(endpoint=endpoint,logger=MagicMock(),resumable_source_manager=manager, # type: ignore[arg-type]+ api_version=api_version,**incremental,):rows.extend(batch)@@ -299,6 +301,45 @@ class TestV1Lists:assert rows == [{"id": "wh1", "name": "github intake"}]+class TestVersionDispatch:+ @parameterized.expand([("v1", "/v1/webhooks"), ("v2", "/v2/webhooks")])+ def test_webhooks_endpoint_follows_the_source_pin(self, api_version: str, expected_path: str) -> None:+ # Webhooks is served under both API versions; the source pin decides which inventory a+ # source reads. A v1 pin must stay on the original path (existing syncs byte-for-byte), a+ # v2 pin must move to the v2 inventory. The url field is capability-bearing and dropped on+ # either version.+ seen_urls: list[str] = []++ def fake_fetch(session: Any, url: str, headers: dict, logger: Any, params: dict | None = None) -> Any:+ seen_urls.append(url)+ return {+ "data": [{"id": "wh1", "name": "intake", "url": "https://inn.gs/secret"}],+ "page": {"hasMore": False},+ }++ rows, _ = _run_rows("webhooks", fake_fetch, api_version=api_version)+ assert seen_urls[0] == f"https://api.inngest.com{expected_path}"+ assert rows == [{"id": "wh1", "name": "intake"}]++ @parameterized.expand(+ [+ # Cancellations only exist in v1 and the envs inventory only in v2, so a pin on the+ # other version must not relocate them off their only compatible home (a 404 otherwise).+ ("cancellations", "v2", "/v1/cancellations"),+ ("environments", "v1", "/v2/envs"),+ ]+ )+ def test_version_locked_endpoint_ignores_the_pin(self, endpoint: str, api_version: str, expected_path: str) -> None:+ seen_urls: list[str] = []++ def fake_fetch(session: Any, url: str, headers: dict, logger: Any, params: dict | None = None) -> Any:+ seen_urls.append(url)+ return {"data": [{"id": "x1"}], "page": {"hasMore": False}}++ _run_rows(endpoint, fake_fetch, api_version=api_version)+ assert seen_urls[0] == f"https://api.inngest.com{expected_path}"++class TestValidateCredentials:@parameterized.expand([("ok", 200, True), ("unauthorized", 401, False), ("forbidden", 403, False)])def test_status_maps_to_validity(self, _name: str, status: int, expected: bool) -> None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest_source.pyindex b6c3f8662ebb..c91f968d1a3d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/inngest/tests/test_inngest_source.py@@ -139,6 +139,32 @@ class TestInngestSource:assert kwargs["should_use_incremental_field"] is Trueassert kwargs["db_incremental_field_last_value"] == "2026-07-01T00:00:00Z"+ def test_defaults_new_sources_to_v2(self) -> None:+ # New sources are stamped with default_version; this locks the bump to v2 (the generic+ # registry invariant only checks default == supported_versions[-1], so a revert to v1+ # would pass it).+ assert self.source.supported_versions == ("v1", "v2")+ assert self.source.default_version == "v2"++ @parameterized.expand(+ [+ ("no_pin_resolves_to_default", None, "v2"),+ ("v1_pin_honored", "v1", "v1"),+ ("v2_pin_honored", "v2", "v2"),+ ]+ )+ def test_source_for_pipeline_threads_the_resolved_api_version(+ self, _name: str, pin: Optional[str], expected: str+ ) -> None:+ # A pinned source must sync under its own version, not the default — dropping the resolve+ # would silently read version-mobile tables (webhooks) from the wrong API version.+ config = InngestSourceConfig(signing_key="signkey-prod-test")+ inputs = _source_inputs("webhooks")+ inputs.api_version = pin+ with patch.object(source_module, "inngest_source") as mock_source:+ self.source.source_for_pipeline(config, MagicMock(), inputs)+ assert mock_source.call_args.kwargs["api_version"] == expected+def test_source_for_pipeline_normalizes_blank_environment_to_none(self) -> None:# An empty-string environment must not be sent as an X-Inngest-Env header — the API would# try to resolve a branch environment named "".