: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 endpoint.incremental keys (#70616)
Tom Owersba225b76dbe2
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 96e9c3569f70..00bb9e9e953d 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@@ -337,14 +337,39 @@ def _validate_resource_graph(manifest: dict[str, Any]) -> dict[str, Optional[Resreturn resolved+# Keys the Custom source accepts inside ``endpoint.incremental``. The REST engine's+# ``Incremental(**config)`` constructor takes a fixed set of kwargs, so any other key+# (e.g. a dlt option copied from upstream docs) reaches it as an unexpected kwarg and+# crashes sync setup with a ``TypeError`` the pipeline doesn't convert to non-retryable —+# Temporal then retries a deterministic failure. ``cursor_type``/``datetime_format`` are+# custom-source-only hints stripped before the engine (see+# ``_strip_engine_unsupported_incremental_keys``); the rest map to the engine directly.+_SUPPORTED_INCREMENTAL_KEYS = frozenset(+ {+ "start_param",+ "end_param",+ "cursor_path",+ "initial_value",+ "end_value",+ "last_value_func",+ "row_order",+ "convert",+ "transform",+ "cursor_type",+ "datetime_format",+ }+)++def _validate_incremental_configs(manifest: dict[str, Any]) -> None:"""Reject incremental config values that would deterministically crash at sync time.The structural schema doesn't model ``endpoint.incremental``, so hand-authoredmistakes here would otherwise only surface mid-sync: a non-string ``datetime_format``as a strftime error (and only from the second sync onward, once a watermark is- stored), and a missing ``start_param`` as a bare ``KeyError`` the REST engine raises- from ``setup_incremental_object``.+ stored), a missing ``start_param`` as a bare ``KeyError`` the REST engine raises+ from ``setup_incremental_object``, and an unsupported key as a ``TypeError`` from the+ engine's ``Incremental(**config)`` constructor."""for resource in manifest.get("resources") or []:if not isinstance(resource, dict):@@ -353,6 +378,13 @@ def _validate_incremental_configs(manifest: dict[str, Any]) -> None:incremental = endpoint.get("incremental") if isinstance(endpoint, dict) else Noneif not isinstance(incremental, dict):continue+ unsupported = sorted(set(incremental) - _SUPPORTED_INCREMENTAL_KEYS)+ if unsupported:+ raise ManifestValidationError(+ f"Resource {resource.get('name')!r}: endpoint.incremental has unsupported "+ f"{'keys' if len(unsupported) > 1 else 'key'} {', '.join(unsupported)}. "+ f"Allowed keys: {', '.join(sorted(_SUPPORTED_INCREMENTAL_KEYS))}"+ )datetime_format = incremental.get("datetime_format")if datetime_format is not None and not isinstance(datetime_format, str):raise ManifestValidationError(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 43cc4b3a39ec..2a515ceca4e4 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@@ -2462,6 +2462,41 @@ class TestCustomSourceIncrementalStartParam(SimpleTestCase):assert err is not None and "start_param" in err and "'users'" in err+class TestCustomSourceIncrementalUnsupportedKeys(SimpleTestCase):+ def _manifest(self) -> dict:+ manifest = _minimal_manifest()+ manifest["resources"][0]["endpoint"]["incremental"] = {+ "cursor_path": "updated_at",+ "start_param": "since",+ "upstream_row_order": "asc",+ }+ 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=True,+ db_incremental_field_last_value=None,+ )+ with self.assertRaises(NonRetryableException) as ctx:+ source.source_for_pipeline(config, inputs)+ assert "upstream_row_order" 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 "upstream_row_order" 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."""