: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): fail fast when endpoint.incremental omits start_param (#68717)
Tom Owers7b7e40ad8ec8
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 5e6bf4c052e9..96e9c3569f70 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@@ -340,9 +340,11 @@ def _validate_resource_graph(manifest: dict[str, Any]) -> dict[str, Optional[Resdef _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 a hand-authored- non-string ``datetime_format`` would otherwise only surface mid-sync, and only- from the second sync onward (formatting needs a stored watermark).+ The structural schema doesn't model ``endpoint.incremental``, so hand-authored+ mistakes 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``."""for resource in manifest.get("resources") or []:if not isinstance(resource, dict):@@ -357,6 +359,12 @@ def _validate_incremental_configs(manifest: dict[str, Any]) -> None:f"Resource {resource.get('name')!r}: endpoint.incremental.datetime_format must be a string "'strftime pattern (e.g. "%Y-%m-%dT%H:%M:%SZ")')+ start_param = incremental.get("start_param")+ if not isinstance(start_param, str) or not start_param:+ raise ManifestValidationError(+ f"Resource {resource.get('name')!r}: endpoint.incremental.start_param is required and must be a "+ "non-empty string naming the query parameter used to send the cursor value to the API"+ )# Plain-English replacements for the pydantic constraint messages users hit most@@ -1022,6 +1030,11 @@ class CustomSource(SimpleSource[CustomSourceConfig]):]engine_manifest = cast(RESTAPIConfig, {**manifest, "resources": engine_resources})+ # Backstop for manifests stored before create-time validation covered this: an+ # 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})+# The engine serializes a datetime watermark via str() (space-separated),# which strict APIs reject — format it to the declared wire format first.last_value = inputs.db_incremental_field_last_value if inputs.should_use_incremental_field else Nonediff --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 3188ab752773..43cc4b3a39ec 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@@ -2424,6 +2424,44 @@ class TestCustomSourceIncrementalDatetimeFormat(SimpleTestCase):assert child_params.get("since") == "2026-06-08T12:53:34Z"+class TestCustomSourceIncrementalStartParam(SimpleTestCase):+ _OMIT = object()++ def _manifest(self, start_param) -> dict:+ manifest = _minimal_manifest()+ incremental: dict = {"cursor_path": "updated_at"}+ if start_param is not self._OMIT:+ incremental["start_param"] = start_param+ manifest["resources"][0]["endpoint"]["incremental"] = incremental+ return manifest++ @parameterized.expand([("missing", _OMIT), ("empty", ""), ("non_string", 123)])+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.custom.source.rest_api_resources")+ def test_missing_start_param_raises_non_retryable(self, _name, start_param, mock_resources):+ mock_resources.return_value = [_fake_resource("users")]+ source = CustomSource()+ config = CustomSourceConfig(manifest_json=json.dumps(self._manifest(start_param)))+ 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 "start_param" in str(ctx.exception)+ mock_resources.assert_not_called()++ @parameterized.expand([("missing", _OMIT), ("empty", "")])+ def test_missing_start_param_rejected_at_validation(self, _name, start_param):+ source = CustomSource()+ config = CustomSourceConfig(manifest_json=json.dumps(self._manifest(start_param)), auth_token="abc")+ ok, err = source.validate_credentials(config, team_id=999)+ assert ok is False+ assert err is not None and "start_param" 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."""