: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
fix(custom): reject unsupported paginator config keys before sync (#72774)
Tom Owersef65ee1d0d92
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.pyindex 2b97c3f757c9..5ddeaf83ceff 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py@@ -1,6 +1,7 @@import copyimport jsonimport hashlib+import inspectimport graphlibfrom collections.abc import Callablefrom datetime import date@@ -57,6 +58,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.config_setup import (build_resource_dependency_graph,create_auth,+ get_paginator_class,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (EndpointResource,@@ -407,6 +409,52 @@ def _validate_incremental_configs(manifest: dict[str, Any]) -> None:)+def _validate_paginator_configs(manifest: dict[str, Any]) -> None:+ """Reject paginator config keys that would deterministically crash at sync time.++ A dict paginator config reaches the REST engine as ``PaginatorClass(**config)`` (minus+ ``type``), so an unsupported key — e.g. one copied from newer dlt docs — arrives as an+ unexpected kwarg and crashes sync setup with a ``TypeError`` the pipeline doesn't convert+ to non-retryable, so Temporal retries a deterministic failure. An unknown ``type`` is+ caught here too, rather than surfacing as a bare engine ``ValueError`` mid-sync.+ """+ client = manifest.get("client")+ if isinstance(client, dict):+ _check_paginator_config(client.get("paginator"), "client.paginator")++ for resource in manifest.get("resources") or []:+ if not isinstance(resource, dict):+ continue+ endpoint = resource.get("endpoint")+ paginator = endpoint.get("paginator") if isinstance(endpoint, dict) else None+ _check_paginator_config(paginator, f"Resource {resource.get('name')!r}: endpoint.paginator")+++def _check_paginator_config(paginator: Any, location: str) -> None:+ # Only a dict is spread into the paginator constructor as kwargs; a string names a built-in+ # and an instance is used as-is, so neither reaches the unexpected-kwarg path.+ if not isinstance(paginator, dict):+ return+ try:+ paginator_class = get_paginator_class(cast(Any, paginator.get("type", "auto")))+ except ValueError as exc:+ raise ManifestValidationError(f"{location}: {exc}") from exc+ # "auto" (and any type mapped to None) applies no paginator, so extra keys are ignored.+ if paginator_class is None:+ return+ supported = {+ name+ for name, param in inspect.signature(paginator_class).parameters.items()+ if param.kind in (param.POSITIONAL_OR_KEYWORD, param.KEYWORD_ONLY)+ }+ unsupported = sorted(set(paginator) - {"type"} - supported)+ if unsupported:+ raise ManifestValidationError(+ f"{location} has unsupported {'keys' if len(unsupported) > 1 else 'key'} "+ f"{', '.join(unsupported)}. Allowed keys: {', '.join(sorted(supported))}"+ )++# Plain-English replacements for the pydantic constraint messages users hit most# when hand-authoring a manifest; an unmapped error keeps pydantic's own wording._VALIDATION_MESSAGE_OVERRIDES = {@@ -890,6 +938,7 @@ class CustomSource(SimpleSource[CustomSourceConfig]):# map feeds the probe's child filter below.resolved = _validate_resource_graph(manifest)_validate_incremental_configs(manifest)+ _validate_paginator_configs(manifest)except ManifestValidationError as exc:return False, str(exc)@@ -1140,6 +1189,7 @@ class CustomSource(SimpleSource[CustomSourceConfig]):# endpoint.incremental block missing start_param crashes the engine with a bare,# retryable KeyError. Reject it as a ValueError so it fails fast and non-retryably._validate_incremental_configs({"resources": engine_resources})+ _validate_paginator_configs({"client": manifest.get("client"), "resources": engine_resources})# The engine serializes a datetime watermark via str() (space-separated),# which strict APIs reject — format it to the declared wire format first.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.pyindex 693f391e5106..c788ff08f07e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py@@ -2525,6 +2525,41 @@ class TestCustomSourceIncrementalUnsupportedKeys(SimpleTestCase):assert err is not None and "upstream_row_order" in err and "'users'" in err+class TestCustomSourcePaginatorUnsupportedKeys(SimpleTestCase):+ def _manifest(self) -> dict:+ manifest = _minimal_manifest()+ manifest["resources"][0]["endpoint"]["paginator"] = {+ "type": "offset",+ "limit": 100,+ "limit_body_path": "meta.limit",+ }+ return manifest++ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.custom.source.rest_api_resources")+ def test_unsupported_key_raises_non_retryable_before_engine(self, mock_resources):+ mock_resources.return_value = [_fake_resource("users")]+ source = CustomSource()+ config = CustomSourceConfig(manifest_json=json.dumps(self._manifest()))+ inputs = MagicMock(+ team_id=1,+ schema_name="users",+ job_id="job-1",+ should_use_incremental_field=False,+ db_incremental_field_last_value=None,+ )+ with self.assertRaises(NonRetryableException) as ctx:+ source.source_for_pipeline(config, inputs)+ assert "limit_body_path" in str(ctx.exception)+ mock_resources.assert_not_called()++ def test_unsupported_key_rejected_at_validation(self):+ source = CustomSource()+ config = CustomSourceConfig(manifest_json=json.dumps(self._manifest()), auth_token="abc")+ ok, err = source.validate_credentials(config, team_id=999)+ assert ok is False+ assert err is not None and "limit_body_path" in err and "'users'" in err++def _apikey_manifest() -> dict:"""A minimal manifest whose auth is an api_key in a query param, so theinjected secret is registered for value-based redaction."""