: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 Notion API version 2026-03-11 (#71667)
Tom Owerse5b2fedee3da
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 6af7c06b3c60..bd4dbf48fef4 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -69,3 +69,6 @@ After you finish a version-update or deprecation PR using this skill, **append w- A new version label doesn't imply new paths: vendors ship a "v2" that still serves resources at `/v1/`, or replace the resource API entirely — check the docs per resource before building `/{version}/{resource}` URLs. A tell-tale in your own diff: needing a different probe/validation endpoint for the new version proves the resource sets diverge, so the sync paths need branching too.- Grep every place the source builds a client or URL (sync, discovery, probes, error matchers, webhooks) when bumping — the ones outside the sync path silently stay on default/legacy versions.- Simplecast: current API (api.simplecast.com + Bearer) _is_ "2.0" and the `UNVERSIONED_API_VERSION` ("v1") pin already hit it, so both labels resolve to the same live API — adding "2.0" as the new default is a pure declaration change with no wire divergence. Header-based version selection is announced but unshipped, so don't thread a speculative version header onto requests: declare `supported_versions`/`default_version` now and defer the wire dispatch until the real header contract exists (a no-op header ships risk with no present benefit).+- Notion 2026-03-11: for read-only syncs a new version is often header-only — its breaking changes (`archived`->`in_trash`, `transcription`->`meeting_notes` block type, `after`->`position` on _append_ block children) only touch response fields or write paths we never call, so with an auto-inferred schema the sole dispatch is threading the resolved version into the request header. No per-version module needed.+- When the request layer hardcodes the version as a module constant (e.g. `NOTION_VERSION`), the dispatch is: add a param through the client/session builders (`notion_source` -> `get_rows` -> `_build_session` -> `_get_headers`), pass `self.resolve_api_version(inputs.api_version)` from `source_for_pipeline`, and give the standalone `validate_credentials(token, api_version)` `self.default_version` (creation-time, version-agnostic probe).+- Test pattern that stayed cheap: parameterize the header builder over supported versions (header carries requested version) + mock `notion_source` in the source module and assert `call_args.kwargs["api_version"]` for none/legacy/new pins (resolution + threading in one).diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/canonical_descriptions.pyindex 0ecb2d9c2b1b..947da6fce3ff 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/canonical_descriptions.py@@ -18,6 +18,9 @@ _COMMON_COLUMNS = {"created_by": "Reference to the user who created the object.","last_edited_by": "Reference to the user who last edited the object.","archived": "Whether the object has been archived (moved to trash).",+ # API version 2026-03-11 renamed `archived` to `in_trash`; describe both so every version's+ # response is covered (unused keys simply fall through).+ "in_trash": "Whether the object is in the trash (the 2026-03-11 rename of `archived`).","parent": "Reference to the parent object that contains this one.",}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/notion.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/notion.pyindex 40b57d9a6186..9da35550791e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/notion.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/notion.py@@ -19,11 +19,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.notion.set)NOTION_BASE_URL = "https://api.notion.com"-# Pinned API version. 2025-09-03 is the current official SDK default and introduces the-# data sources model: a "database" is a container, and the schema-bearing tables are-# "data sources". For the endpoints we use this only changes the search object filter-# ("database" -> "data_source"); users/blocks/comments are unaffected.-NOTION_VERSION = "2025-09-03"+# Supported API versions, as opaque Notion-Version header labels (never parsed or ordered). The pin+# is resolved by the source class and threaded down to the request headers.+# - 2025-09-03 introduced the data sources model: a "database" is a container, and the+# schema-bearing tables are "data sources", so the databases stream filters search on+# "data_source" instead of "database".+# - 2026-03-11 is a stable follow-up. For the read-only endpoints we consume it only renames+# response fields (archived -> in_trash, the transcription block type -> meeting_notes) and+# reshapes the append-block-children request, which we never call; the search object filter is+# still "data_source". So for our sync the two versions differ only in this header value, and the+# auto-inferred schema absorbs the renamed response fields.+NOTION_VERSION_2025_09_03 = "2025-09-03"+NOTION_VERSION_2026_03_11 = "2026-03-11"CHUNK_SIZE = 2000CHUNK_SIZE_BYTES = 100 * 1024 * 1024@@ -101,18 +108,18 @@ class _RateLimiter:self._last_request_at = time.monotonic()-def _get_headers(token: str) -> dict[str, str]:+def _get_headers(token: str, api_version: str) -> dict[str, str]:return {"Authorization": f"Bearer {token}",- "Notion-Version": NOTION_VERSION,+ "Notion-Version": api_version,"Content-Type": "application/json",}-def _build_session(token: str) -> requests.Session:+def _build_session(token: str, api_version: str) -> requests.Session:# Disable the tracked session's built-in urllib3 retries so tenacity is the single retry layer;# one session is reused across every request of a stream to keep connection pooling/keep-alive.- return make_tracked_session(headers=_get_headers(token), redact_values=(token,), retry=Retry(total=0))+ return make_tracked_session(headers=_get_headers(token, api_version), redact_values=(token,), retry=Retry(total=0))def _parse_retry_after(value: str | None) -> float | None:@@ -201,9 +208,9 @@ def _request(return response.json()-def validate_credentials(token: str) -> tuple[bool, str | None]:+def validate_credentials(token: str, api_version: str) -> tuple[bool, str | None]:try:- session = make_tracked_session(headers=_get_headers(token), redact_values=(token,))+ session = make_tracked_session(headers=_get_headers(token, api_version), redact_values=(token,))response = session.get(f"{NOTION_BASE_URL}/v1/users/me", timeout=10)except Exception as e:return False, str(e)@@ -494,9 +501,10 @@ def get_rows(endpoint: str,logger: FilteringBoundLogger,resumable_source_manager: ResumableSourceManager[NotionResumeConfig],+ api_version: str,) -> Iterator[Any]:config = NOTION_ENDPOINTS[endpoint]- session = _build_session(token)+ session = _build_session(token, api_version)throttle = _RateLimiter(NOTION_MIN_REQUEST_INTERVAL_SECONDS)if config.stream_type == "search":@@ -516,6 +524,7 @@ def notion_source(endpoint: str,logger: FilteringBoundLogger,resumable_source_manager: ResumableSourceManager[NotionResumeConfig],+ api_version: str,) -> SourceResponse:config = NOTION_ENDPOINTS[endpoint]@@ -526,6 +535,7 @@ def notion_source(endpoint=endpoint,logger=logger,resumable_source_manager=resumable_source_manager,+ api_version=api_version,),primary_keys=["id"],partition_count=1,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/settings.pyindex e2be57808991..1e0094155e84 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/settings.py@@ -17,7 +17,7 @@ class NotionEndpointConfig:# last_edited_time changes on every edit so it is unsuitable.partition_key: Optional[str] = None# For "search" streams: the Notion object type to filter to ("page" or "data_source").- # Under API version 2025-09-03 the schema-bearing "database" tables are returned as+ # From API version 2025-09-03 onward the schema-bearing "database" tables are returned as# "data_source" objects, so the databases stream filters on "data_source".object_filter: Optional[str] = Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.pyindex 28ab87f9600b..1a340fe19b85 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@@ -22,6 +22,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import SourceSchemafrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import NotionSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.notion.notion import (+ NOTION_VERSION_2025_09_03,+ NOTION_VERSION_2026_03_11,NotionResumeConfig,notion_source,validate_credentials as validate_notion_credentials,@@ -35,8 +37,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass NotionSource(ResumableSource[NotionSourceConfig, NotionResumeConfig]):- supported_versions = ("2025-09-03",)- default_version = "2025-09-03"+ supported_versions = (NOTION_VERSION_2025_09_03, NOTION_VERSION_2026_03_11)+ default_version = NOTION_VERSION_2026_03_11api_docs_url = "https://developers.notion.com/page/changelog"lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@@ -113,7 +115,9 @@ Then **share** each page or database you want to sync with the integration (viadef validate_credentials(self, config: NotionSourceConfig, team_id: int, schema_name: Optional[str] = None) -> tuple[bool, str | None]:- return validate_notion_credentials(config.api_key)+ # 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)def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[NotionResumeConfig]:return ResumableSourceManager[NotionResumeConfig](inputs, NotionResumeConfig)@@ -129,4 +133,5 @@ Then **share** each page or database you want to sync with the integration (viaendpoint=inputs.schema_name,logger=inputs.logger,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/notion/tests/test_notion.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion.pyindex e08f2190b3e0..e9fb68319c84 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion.py@@ -12,7 +12,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.notion.notMAX_BLOCK_DEPTH,MAX_CHILD_PAGES_PER_PARENT,MAX_RETRY_AFTER_SECONDS,- NOTION_VERSION,+ NOTION_VERSION_2025_09_03,+ NOTION_VERSION_2026_03_11,NotionBadRequestError,NotionNotFoundError,NotionResumeConfig,@@ -90,10 +91,11 @@ class _FakeRetryState:class TestNotion:- def test_headers_include_bearer_token_and_version(self) -> None:- headers = _get_headers("ntn_secret")+ @parameterized.expand([(NOTION_VERSION_2025_09_03,), (NOTION_VERSION_2026_03_11,)])+ def test_headers_carry_requested_version(self, api_version: str) -> None:+ headers = _get_headers("ntn_secret", api_version)assert headers["Authorization"] == "Bearer ntn_secret"- assert headers["Notion-Version"] == NOTION_VERSION+ assert headers["Notion-Version"] == api_versionassert headers["Content-Type"] == "application/json"@parameterized.expand([("page",), ("data_source",)])@@ -463,7 +465,7 @@ class TestNotion:def test_validate_credentials_status_mapping(self, status_code: int, expected_valid: bool) -> None:session = FakeSession([FakeResponse({}, status_code=status_code)])with mock.patch(f"{MODULE}.make_tracked_session", return_value=session):- valid, message = validate_credentials("tok")+ valid, message = validate_credentials("tok", NOTION_VERSION_2026_03_11)assert valid is expected_validif expected_valid:@@ -473,7 +475,7 @@ class TestNotion:def test_validate_credentials_handles_exception(self) -> None:with mock.patch(f"{MODULE}.make_tracked_session", side_effect=requests.ConnectionError("boom")):- valid, message = validate_credentials("tok")+ valid, message = validate_credentials("tok", NOTION_VERSION_2026_03_11)assert valid is Falseassert message == "boom"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.pyindex f1e3e9e1a5ea..d46b9616c64c 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@@ -18,7 +18,7 @@ from products.warehouse_sources.backend.types import ExternalDataSourceTypeNOTION_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.notion.notion"-def _make_inputs(schema_name: str = "pages") -> SourceInputs:+def _make_inputs(schema_name: str = "pages", api_version: str | None = None) -> SourceInputs:return SourceInputs(schema_name=schema_name,schema_id="schema-id",@@ -32,6 +32,7 @@ def _make_inputs(schema_name: str = "pages") -> SourceInputs:job_id="job-id",logger=structlog.get_logger(),reset_pipeline=False,+ api_version=api_version,)@@ -48,6 +49,30 @@ class TestNotionSource:def test_source_type(self) -> None:assert self.source.source_type == ExternalDataSourceType.NOTION+ def test_new_sources_default_to_latest_version(self) -> None:+ # New sources are stamped with default_version, so a regression here silently pins them to+ # the older API. Both versions must stay supported so existing pins keep resolving.+ assert self.source.default_version == "2026-03-11"+ assert set(self.source.supported_versions) == {"2025-09-03", "2026-03-11"}++ @parameterized.expand(+ [+ ("no_pin_uses_default", None, "2026-03-11"),+ ("legacy_pin_honored", "2025-09-03", "2025-09-03"),+ ("new_pin_honored", "2026-03-11", "2026-03-11"),+ ]+ )+ def test_source_for_pipeline_threads_resolved_version(+ self, _name: str, pin: str | None, expected_version: str+ ) -> None:+ inputs = _make_inputs("pages", api_version=pin)+ manager = self.source.get_resumable_source_manager(inputs)+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.notion.source.notion_source"+ ) as notion_source_mock:+ self.source.source_for_pipeline(NotionSourceConfig(api_key="tok"), manager, inputs)+ assert notion_source_mock.call_args.kwargs["api_version"] == expected_version+def test_source_config_is_released_with_api_key_field(self) -> None:config = self.source.get_source_configassert config.releaseStatus == ReleaseStatus.ALPHA