: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(data-warehouse): stop fillout submissions syncs sending rejected params (#103687)
Tom Owersb1744eb8b61f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.pyindex 42afbc2b9198..8b6b739bb0d6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py@@ -1,4 +1,4 @@-from collections.abc import Iterable+from collections.abc import Callable, Iterablefrom typing import Any, Optional, castfrom requests import Request, Response@@ -50,14 +50,15 @@ def _validated_api_base_url(api_base_url: str | None) -> str:def _format_fillout_datetime(value: Any) -> str:"""Format the incremental watermark for Fillout's `afterDate` filter.- Truncates to whole seconds, which rounds the lower bound *down* — so a sync+ Truncates to whole milliseconds, matching the precision Fillout itself reports+ `submissionTime` at. Truncating rounds the lower bound *down* — so a syncre-fetches at most a few boundary rows (the merge dedupes them) rather thanskipping any."""normalized_value = coerce_datetime_to_utc(value)if normalized_value is None:return str(value)- return normalized_value.strftime("%Y-%m-%dT%H:%M:%SZ")+ return f"{normalized_value.strftime('%Y-%m-%dT%H:%M:%S')}.{normalized_value.microsecond // 1000:03d}Z"def _fillout_incremental_window(cursor_path: str) -> IncrementalConfig:@@ -66,13 +67,25 @@ def _fillout_incremental_window(cursor_path: str) -> IncrementalConfig:return {"cursor_path": cursor_path,"start_param": "afterDate",- # Not `...T00:00:00Z`: Fillout's API rejects an `afterDate` of exactly the Unix epoch- # with a 400 "Invalid date", so the first (pre-watermark) sync uses one second past it.- "initial_value": "1970-01-01T00:00:01Z","convert": _format_fillout_datetime,}+def _no_incremental_window(cursor_path: str) -> IncrementalConfig | None:+ # Fillout has no `afterDate` value meaning "since the beginning of time", and the endpoint+ # returns every submission when the param is absent. So a sync with no watermark yet sends+ # no `afterDate` at all rather than a sentinel date the API can reject.+ return None+++def _incremental_window_factory(+ db_incremental_field_last_value: Optional[Any],+) -> Callable[[str], IncrementalConfig | None]:+ if db_incremental_field_last_value is None:+ return _no_incremental_window+ return _fillout_incremental_window++def _auth_headers(api_key: str) -> dict[str, str]:return {"Authorization": f"Bearer {api_key}", "Accept": "application/json"}@@ -88,10 +101,11 @@ def _rest_api_client_config(base_api_url: str, api_key: str) -> ClientConfig:class FilloutSubmissionsPaginator(OffsetPaginator):"""Limit/offset paginator for `/forms/{formId}/submissions`.- Pins `sort=asc` (oldest-first, matching the ascending incremental watermark) and- `status=finished` (Fillout's default; we don't want in-progress drafts). `totalResponses`- reflects the `afterDate`-filtered count, so the walk stops at the watermark on incremental- syncs rather than re-reading each form's full history.+ Pins `sort=asc`, oldest-first, matching the ascending incremental watermark. No `status`+ param: `finished` is already Fillout's default, so sending it only added a way for the+ request to be rejected. `totalResponses` reflects the `afterDate`-filtered count, so the+ walk stops at the watermark on incremental syncs rather than re-reading each form's full+ history."""def __init__(self, limit: int) -> None:@@ -105,7 +119,6 @@ class FilloutSubmissionsPaginator(OffsetPaginator):def init_request(self, request: Request) -> None:super().init_request(request)request.params.setdefault("sort", "asc")- request.params.setdefault("status", "finished")def validate_credentials(@@ -241,7 +254,7 @@ def fillout_source(db_incremental_field_last_value=db_incremental_field_last_value,should_use_incremental_field=should_use_incremental_field,incremental_field=incremental_field,- incremental_config_factory=_fillout_incremental_window,+ incremental_config_factory=_incremental_window_factory(db_incremental_field_last_value),page_size_param="limit",parent_endpoint_extra={"paginator": SinglePagePaginator(),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.pyindex 9f72bcd8dc93..daca7b2c2246 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py@@ -9,8 +9,8 @@ from parameterized import parameterizedfrom products.warehouse_sources.backend.temporal.data_imports.sources.fillout.fillout import (FilloutSubmissionsPaginator,- _fillout_incremental_window,_format_fillout_datetime,+ _incremental_window_factory,_validated_api_base_url,fillout_source,get_resource,@@ -32,19 +32,20 @@ class _FakeDltResource:class TestFilloutTransport:- def test_submissions_paginator_init_sets_offset_limit_sort_status(self) -> None:+ def test_submissions_paginator_init_sets_offset_limit_sort(self) -> None:paginator = FilloutSubmissionsPaginator(limit=150)request = Mock()- request.params = {"afterDate": "2026-01-01T00:00:00Z"}+ request.params = {"afterDate": "2026-01-01T00:00:00.000Z"}paginator.init_request(request)assert request.params["offset"] == 0assert request.params["limit"] == 150assert request.params["sort"] == "asc"- assert request.params["status"] == "finished"+ # `finished` is Fillout's default, so the request carries no `status` of its own.+ assert "status" not in request.params# The incremental window filter is left untouched.- assert request.params["afterDate"] == "2026-01-01T00:00:00Z"+ assert request.params["afterDate"] == "2026-01-01T00:00:00.000Z"@parameterized.expand([@@ -85,19 +86,29 @@ class TestFilloutTransport:@parameterized.expand([- ("naive_datetime", datetime(2026, 3, 1, 12, 30, 45), "2026-03-01T12:30:45Z"),- ("aware_datetime", datetime(2026, 3, 1, 12, 30, 45, tzinfo=UTC), "2026-03-01T12:30:45Z"),+ ("naive_datetime", datetime(2026, 3, 1, 12, 30, 45), "2026-03-01T12:30:45.000Z"),+ ("aware_datetime", datetime(2026, 3, 1, 12, 30, 45, tzinfo=UTC), "2026-03-01T12:30:45.000Z"),+ # Sub-millisecond precision truncates down, so the window never skips a row.+ ("microseconds", datetime(2026, 3, 1, 12, 30, 45, 123_999, tzinfo=UTC), "2026-03-01T12:30:45.123Z"),("passthrough_string", "1970-01-01T00:00:00Z", "1970-01-01T00:00:00Z"),])def test_format_fillout_datetime(self, _name, value, expected) -> None:assert _format_fillout_datetime(value) == expected- def test_fillout_incremental_window_initial_value_is_not_unix_epoch(self) -> None:- # Fillout's API 400s on an `afterDate` of exactly 1970-01-01T00:00:00Z (any- # millisecond precision), so the pre-watermark sentinel must land elsewhere.- config = _fillout_incremental_window("submissionTime")- assert config["initial_value"] not in ("1970-01-01T00:00:00Z", "1970-01-01T00:00:00.000Z")+ def test_incremental_window_omitted_without_a_watermark(self) -> None:+ # Fillout 400s the submissions request when `afterDate` carries a sentinel date, so a+ # sync with no watermark yet must send no `afterDate` at all.+ assert _incremental_window_factory(None)("submissionTime") is None++ def test_incremental_window_binds_afterDate_to_the_watermark(self) -> None:+ config = _incremental_window_factory(datetime(2026, 3, 1, tzinfo=UTC))("submissionTime")++ assert config is not None+ assert config["start_param"] == "afterDate"+ assert config["cursor_path"] == "submissionTime"+ # No fallback date: the watermark is the only value `afterDate` is ever given.+ assert "initial_value" not in configdef test_validated_api_base_url_rejects_unknown(self) -> None:with pytest.raises(@@ -256,14 +267,14 @@ class TestFilloutTransport:@parameterized.expand([- ("incremental", True, datetime(2026, 3, 1, tzinfo=UTC)),- ("first_sync", True, None),- ("non_incremental", False, datetime(2026, 3, 1, tzinfo=UTC)),+ ("incremental", True, datetime(2026, 3, 1, tzinfo=UTC), True),+ ("first_sync", True, None, False),+ ("non_incremental", False, datetime(2026, 3, 1, tzinfo=UTC), True),])@patch("products.warehouse_sources.backend.temporal.data_imports.sources.fillout.fillout.build_dependent_resource")def test_fillout_source_submissions_passes_watermark(- self, _name, should_use_incremental_field, last_value, mock_build_dependent_resource+ self, _name, should_use_incremental_field, last_value, expects_after_date, mock_build_dependent_resource) -> None:mock_build_dependent_resource.return_value = iter([])@@ -281,6 +292,11 @@ class TestFilloutTransport:assert kwargs["should_use_incremental_field"] is should_use_incremental_fieldassert kwargs["db_incremental_field_last_value"] == last_value+ # Without a watermark the factory yields no incremental config, so the request carries+ # no `afterDate` rather than a sentinel date Fillout rejects.+ window = kwargs["incremental_config_factory"]("submissionTime")+ assert (window is not None) is expects_after_date+def test_fillout_source_rejects_unknown_api_base_url(self) -> None:with pytest.raises(ValueError,