: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 polar API version 2026-10 (#119192)
Tom Owers4b49bc58f3d9
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 913c67a8a9b1..69554e7641ce 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -104,6 +104,7 @@ The opposite gap also occurs: a reference rendered from one version-blind OpenAP- Don't regenerate schemas for existing customers as part of a version add; schema changes only apply to rows repinned via the (human-run) migration.- Discovery diffs under the SOURCE pin (`sync_new_schemas`, `refresh_schemas`, bulk sync-defaults). A schema-level `api_version` override on a version whose table set differs from the source's version can be disabled/soft-deleted by that diff — keep overrides to short verification windows, not as a long-term way to hold one table on another version.- When a versioned source sends the pin on any vendor call — discovery _or_ sync (a static endpoint catalog doesn't consume it at discovery, but `get_rows` still sends the version header) — add the vendor's version-rejection error signature (e.g. `406`/`410`) to `get_non_retryable_errors`, otherwise a retired pin turns the retry cadence into a permanent error loop with no user-facing surface.+- When the vendor rejects a retired version with a generic status (a plain `404`), its signature also matches every other 404 from that host. Add it only when every URL the source requests is static (list endpoints, no per-id or user-supplied paths), so a 404 can only mean the version, and say so in a comment next to the entry.- A vendor that falls forward on a retired pin — serving the oldest accessible version instead of rejecting the request — has no rejection signature to add. Its sunset still needs the repin migration: the pin silently stops being honored, with no failed sync to surface it.- A version bump can change the auth scheme, not just the wire format. Then the source config needs both credential shapes as optional fields, auth construction dispatches on the resolved version, and `validate_credentials` enforces the pair that version needs — form-level `required` can't express "depends on the pin".- When the new auth scheme is OAuth client credentials, build the sync auth from the framework's `oauth2` auth config, which re-mints an expired token mid-sync. Vendor tokens can live only minutes, so a token minted once per sync expires during a long one.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/polar.py b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/polar.pyindex b271d32ffd50..623a9c73a5d7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/polar.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/polar.py@@ -15,6 +15,16 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.polar.settPOLAR_BASE_URL = "https://api.polar.sh"PAGE_SIZE = 100+# Polar selects a dated API version via the `Polar-Version` header and serves its floating+# "Current" version when the header is absent. The legacy unversioned label ("v1") predates+# this source declaring a version and keeps sending no header, so already-pinned rows make the+# exact request they always have. Dated labels send the header so they stay on that contract.+POLAR_VERSION_2026_10 = "2026-10"++_VERSION_HEADER: dict[str, str] = {+ POLAR_VERSION_2026_10: POLAR_VERSION_2026_10,+}+@dataclasses.dataclassclass PolarResumeConfig:@@ -32,6 +42,17 @@ def _get_polar_session() -> requests.Session:return make_tracked_session()+def _build_headers(api_key: str, api_version: str) -> dict[str, str]:+ headers = {+ "Authorization": f"Bearer {api_key}",+ "Accept": "application/json",+ }+ version = _VERSION_HEADER.get(api_version)+ if version:+ headers["Polar-Version"] = version+ return headers++def _build_url(endpoint: str, page: int) -> str:params: dict[str, str | int] = {"limit": PAGE_SIZE, "page": page}sort_field = ENDPOINT_SORT_FIELDS.get(endpoint)@@ -52,12 +73,10 @@ def _page_from_url(url: str) -> int:def get_rows(api_key: str,endpoint: str,+ api_version: str,resumable_source_manager: ResumableSourceManager[PolarResumeConfig],):- headers = {- "Authorization": f"Bearer {api_key}",- "Accept": "application/json",- }+ headers = _build_headers(api_key, api_version)url: Optional[str] = _build_url(endpoint, page=1)@@ -102,12 +121,14 @@ def get_rows(def polar_source(api_key: str,endpoint: str,+ api_version: str,resumable_source_manager: ResumableSourceManager[PolarResumeConfig],) -> SourceResponse:def items():yield from get_rows(api_key=api_key,endpoint=endpoint,+ api_version=api_version,resumable_source_manager=resumable_source_manager,)@@ -119,11 +140,8 @@ def polar_source()-def validate_credentials(api_key: str, table_name: Optional[str] = None) -> bool:- headers = {- "Authorization": f"Bearer {api_key}",- "Accept": "application/json",- }+def validate_credentials(api_key: str, api_version: str, table_name: Optional[str] = None) -> bool:+ headers = _build_headers(api_key, api_version)session = _get_polar_session()# When called per-schema (the incremental_fields action), a 403 should surfacediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/source.pyindex ff30047c3848..66d52727d8fd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/source.py@@ -9,7 +9,11 @@ from products.warehouse_sources.backend.facade.source_config import (SourceFieldInputConfig,SourceFieldInputConfigType,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ UNVERSIONED_API_VERSION,+ FieldType,+ ResumableSource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (CanonicalDescriptions,)@@ -19,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.schfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.polar import PolarSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.polar.polar import (+ POLAR_VERSION_2026_10,PolarPermissionError,PolarResumeConfig,polar_source,@@ -38,8 +43,8 @@ class PolarSource(ResumableSource[PolarSourceConfig, PolarResumeConfig]):go=("github.com/polarsource/polar-go",),)- supported_versions = ("v1",)- default_version = "v1"+ supported_versions = (UNVERSIONED_API_VERSION, POLAR_VERSION_2026_10)+ default_version = POLAR_VERSION_2026_10api_docs_url = "https://docs.polar.sh/api-reference"lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@@ -92,13 +97,15 @@ class PolarSource(ResumableSource[PolarSourceConfig, PolarResumeConfig]):return {"401 Client Error: Unauthorized for url: https://api.polar.sh": "Your Polar Organization Access Token is invalid or expired. Please generate a new token in Polar and reconnect.","403 Client Error: Forbidden for url: https://api.polar.sh": "Your Polar Organization Access Token does not have the required permissions. Please check the token's scopes in Polar and reconnect.",+ # Polar answers a removed or unknown `Polar-Version` with a 404; the list endpoints are static.+ "404 Client Error: Not Found for url: https://api.polar.sh": "The Polar API version this source uses is no longer supported by Polar. Please contact support to move it to a newer version.",}def validate_credentials(self, config: PolarSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None) -> tuple[bool, str | None]:try:- validate_polar_credentials(config.polar_api_key, schema_name)+ validate_polar_credentials(config.polar_api_key, self.resolve_api_version(api_version), schema_name)return True, Noneexcept PolarPermissionError as e:return False, f"Polar Organization Access Token lacks permissions: {e}"@@ -163,5 +170,6 @@ class PolarSource(ResumableSource[PolarSourceConfig, PolarResumeConfig]):return polar_source(api_key=config.polar_api_key,endpoint=inputs.schema_name,+ api_version=self.resolve_api_version(inputs.api_version),resumable_source_manager=resumable_source_manager,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/test_polar_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/test_polar_source.pyindex f39198ec9720..39422a3efffa 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/polar/test_polar_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/polar/test_polar_source.py@@ -1,16 +1,30 @@+from collections.abc import Iterable+from typing import Any, Optional, cast+from unittest.mock import MagicMock, patchimport requests+from parameterized import parameterizedfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import DEFAULT_RETRYfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.polar import PolarSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.polar import polar as polar_modulefrom products.warehouse_sources.backend.temporal.data_imports.sources.polar.source import PolarSource+_VERSION_CASES = [+ ("legacy_v1_sends_no_header", "v1", None),+ ("2026_10_sends_header", "2026-10", "2026-10"),+ ("unpinned_resolves_to_default", None, "2026-10"),+]+class _FakeResponse:- def __init__(self, status_code: int) -> None:+ def __init__(self, status_code: int, body: Optional[dict] = None) -> None:self.status_code = status_code+ self._body = body or {}++ def json(self) -> dict:+ return self._body@propertydef ok(self) -> bool:@@ -43,3 +57,43 @@ class TestPolarValidateCredentials:assert error is not Noneassert "api.polar.sh" not in errorassert "invalid or expired" in error+++class TestPolarApiVersion:+ @parameterized.expand(_VERSION_CASES)+ def test_sync_requests_send_the_pinned_version(+ self, _name: str, pin: Optional[str], expected_header: Optional[str]+ ) -> None:+ session = MagicMock()+ session.request.return_value = _FakeResponse(+ 200, {"items": [{"id": "cus_1"}], "pagination": {"total_count": 1, "max_page": 1}}+ )+ inputs = MagicMock(schema_name="customers", api_version=pin)+ manager = MagicMock()+ manager.can_resume.return_value = False+ with patch.object(polar_module, "_get_polar_session", return_value=session):+ response = PolarSource().source_for_pipeline(+ PolarSourceConfig(polar_api_key="polar_oat_test"), manager, inputs+ )+ rows = list(cast(Iterable[Any], response.items()))++ assert rows == [[{"id": "cus_1"}]]+ url = session.request.call_args.args[1]+ assert url.startswith("https://api.polar.sh/v1/customers/?")+ headers = session.request.call_args.kwargs["headers"]+ assert headers.get("Polar-Version") == expected_header++ @parameterized.expand(_VERSION_CASES)+ def test_credential_probe_sends_the_pinned_version(+ self, _name: str, pin: Optional[str], expected_header: Optional[str]+ ) -> None:+ session = MagicMock()+ session.request.return_value = _FakeResponse(200)+ with patch.object(polar_module, "_get_polar_session", return_value=session):+ ok, _ = PolarSource().validate_credentials(+ PolarSourceConfig(polar_api_key="polar_oat_test"), team_id=1, api_version=pin+ )++ assert ok is True+ headers = session.request.call_args.kwargs["headers"]+ assert headers.get("Polar-Version") == expected_header