: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(data-warehouse): support partial and started responses for Typeform (#63636)
Luke Beltonec43dcfe8398
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex ecb5fae84e76..4581c252d206 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -45140,6 +45140,9 @@"SourceFieldSelectConfig": {"additionalProperties": false,"properties": {+ "caption": {+ "type": "string"+ },"converter": {"$ref": "#/definitions/SourceFieldSelectConfigConverter"},diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex d8bf3a79d662..c41dbe9e25db 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -6713,6 +6713,7 @@ export interface SourceFieldSelectConfig {defaultValue: stringoptions: SourceFieldSelectConfigOption[]converter?: SourceFieldSelectConfigConverter+ caption?: string}export interface SourceFieldSwitchGroupConfig {diff --git a/posthog/schema.py b/posthog/schema.pyindex bb1c32848138..015927c1054e 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -29134,6 +29134,7 @@ class SourceFieldSelectConfig(BaseModel):model_config = ConfigDict(extra="forbid",)+ caption: str | None = Noneconverter: SourceFieldSelectConfigConverter | None = NonedefaultValue: strlabel: strdiff --git a/products/data_warehouse/frontend/shared/components/forms/SourceForm.test.tsx b/products/data_warehouse/frontend/shared/components/forms/SourceForm.test.tsxnew file mode 100644index 000000000000..5488f2ca99be--- /dev/null+++ b/products/data_warehouse/frontend/shared/components/forms/SourceForm.test.tsx@@ -0,0 +1,30 @@+import { SourceConfig, SourceFieldSelectConfig } from '~/queries/schema/schema-general'++import { sourceFieldToElement } from './SourceForm'++const SELECT_FIELD: SourceFieldSelectConfig = {+ type: 'select',+ name: 'response_types',+ label: 'Responses to sync',+ required: false,+ defaultValue: 'completed',+ options: [+ { label: 'Completed responses only', value: 'completed' },+ { label: 'All responses (including partial & started)', value: 'completed,partial,started' },+ ],+ caption: 'Changing this triggers a full refresh of the responses table.',+}++const SOURCE_CONFIG = { name: 'Typeform', fields: [] } as unknown as SourceConfig++describe('sourceFieldToElement', () => {+ it('renders a select field caption as field help text', () => {+ const element = sourceFieldToElement(SELECT_FIELD, SOURCE_CONFIG)+ expect(element.props.help).toBeTruthy()+ })++ it('omits help when a select field has no caption', () => {+ const element = sourceFieldToElement({ ...SELECT_FIELD, caption: undefined }, SOURCE_CONFIG)+ expect(element.props.help).toBeUndefined()+ })+})diff --git a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsxindex b08ae88709f8..84b87ca18dcb 100644--- a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx@@ -213,6 +213,7 @@ export const sourceFieldToElement = (key={field.name}name={hasOptionFields ? [field.name, 'selection'] : field.name}label={field.label}+ help={field.caption ? <LemonMarkdown className="text-xs">{field.caption}</LemonMarkdown> : undefined}>{({ value, onChange }) => (<>diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.pyindex da23c2ac9fc2..ba6b70af0ce7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py@@ -62,6 +62,7 @@ def build_dependent_resource(incremental_config_factory: Callable[[str], IncrementalConfig] | None = None,parent_endpoint_extra: Endpoint | None = None,child_endpoint_extra: Endpoint | None = None,+ child_params_extra: dict[str, Any] | None = None,page_size_param: str = "limit",) -> Iterable[Any]:parent_config = endpoint_configs[fanout.parent_name]@@ -105,6 +106,8 @@ def build_dependent_resource(},page_size_param: child_config.page_size,}+ if child_params_extra:+ child_params.update(child_params_extra)child_endpoint_config: Endpoint = {"path": child_path,"params": child_params,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.pyindex c7e00195ce65..39b0ff5ecc25 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py@@ -4370,6 +4370,7 @@ class TypeformSourceConfig(config.Config):api_base_url: (Literal["https://api.typeform.com", "https://api.eu.typeform.com", "https://api.typeform.eu"] | None) = config.value(default="https://api.typeform.com")+ response_types: Literal["completed", "completed,partial,started"] | None = config.value(default="completed")@config.configdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/settings.pyindex 7fa1d80f0e4f..1af65c7f11af 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/settings.py@@ -25,6 +25,14 @@ SUBMITTED_AT_INCREMENTAL: IncrementalField = {"field": "submitted_at","field_type": IncrementalFieldType.DateTime,}+# Only completed responses have a `submitted_at`. Partial/started responses omit it and share+# no cursor with completed ones, so the all-responses mode is full-refresh only and partitions+# the responses table by `landed_at` (the one timestamp every response type carries).+LANDED_AT_FIELD = "landed_at"++# Value sent as Typeform's `response_type` query param when incomplete response syncs are enabled.+RESPONSE_TYPE_COMPLETED_ONLY = "completed"+RESPONSE_TYPE_ALL = "completed,partial,started"@dataclassdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/source.pyindex 8517cee2b384..f2084a027a08 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/source.py@@ -27,6 +27,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.typeform.sDEFAULT_TYPEFORM_API_BASE_URL,ENDPOINTS,INCREMENTAL_FIELDS,+ RESPONSE_TYPE_ALL,+ RESPONSE_TYPE_COMPLETED_ONLY,)from products.warehouse_sources.backend.temporal.data_imports.sources.typeform.typeform import (typeform_source,@@ -92,6 +94,26 @@ You can generate a personal access token in your [Typeform account settings](htt),],),+ SourceFieldSelectConfig(+ name="response_types",+ label="Responses to sync",+ required=False,+ defaultValue=RESPONSE_TYPE_COMPLETED_ONLY,+ options=[+ SourceFieldSelectConfigOption(+ label="Completed responses only", value=RESPONSE_TYPE_COMPLETED_ONLY+ ),+ SourceFieldSelectConfigOption(+ label="All responses (including partial & started)", value=RESPONSE_TYPE_ALL+ ),+ ],+ caption=(+ "Completed responses sync incrementally. Including partial & started responses "+ "syncs the whole responses table as a full refresh on every run, since Typeform "+ "has no cursor that covers partial responses. **After changing this, resync the "+ "responses table for the new setting to take effect.**"+ ),+ ),],),releaseStatus=ReleaseStatus.GA,@@ -118,12 +140,18 @@ You can generate a personal access token in your [Typeform account settings](httnames: list[str] | None = None,force_refresh: bool = False,) -> list[SourceSchema]:+ include_partials = (config.response_types or RESPONSE_TYPE_COMPLETED_ONLY) != RESPONSE_TYPE_COMPLETED_ONLY+schemas: list[SourceSchema] = []for endpoint in ENDPOINTS:if names and endpoint not in names:continueincremental_fields = INCREMENTAL_FIELDS.get(endpoint, [])+ # Partial/started responses have no `submitted_at` and share no cursor with completed+ # ones, so the all-responses mode syncs as a full refresh only.+ if endpoint == "responses" and include_partials:+ incremental_fields = []supports_incremental = bool(incremental_fields)schemas.append(SourceSchema(@@ -163,4 +191,5 @@ You can generate a personal access token in your [Typeform account settings](httif inputs.should_use_incremental_fieldelse None,incremental_field=inputs.incremental_field,+ response_types=config.response_types or RESPONSE_TYPE_COMPLETED_ONLY,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform.py b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform.pyindex 37198651c983..8c5e30ba7ed3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform.py@@ -84,6 +84,19 @@ class TestTypeformTransport:assert "since" not in request.paramsassert "until" not in request.params+ def test_responses_paginator_update_request_preserves_response_type(self) -> None:+ paginator = TypeformResponsesPaginator()+ response = Mock()+ paginator.update_state(response, data=[{"token": "tok_1"}])++ request = Mock()+ request.params = {"page_size": 1000, "response_type": "completed,partial,started", "since": "2026-03-01"}+ paginator.update_request(request)++ # response_type must stay on every page, even once we switch to the before cursor+ assert request.params["response_type"] == "completed,partial,started"+ assert request.params["before"] == "tok_1"+def test_responses_paginator_init_request_resets_state_between_forms(self) -> None:paginator = TypeformResponsesPaginator()response = Mock()@@ -300,7 +313,8 @@ class TestTypeformTransport:job_id="job-1",)rows = list(cast(Any, response.items()))- assert rows == [{"response_id": "resp_1", "form_id": "form_1"}]+ # Parent field is renamed (_forms_id -> form_id) and both timestamp columns are guaranteed.+ assert rows == [{"response_id": "resp_1", "form_id": "form_1", "submitted_at": None, "landed_at": None}]assert response.partition_mode == "datetime"# Tokens are only unique within a form, and the API returns responses newest-first.assert response.primary_keys == ["form_id", "token"]@@ -312,7 +326,7 @@ class TestTypeformTransport:def test_typeform_source_responses_passes_items_data_selector_to_fanout(self, mock_build_dependent_resource) -> None:- mock_build_dependent_resource.return_value = iter([])+ mock_build_dependent_resource.return_value.add_map.return_value = iter([])typeform_source(auth_token="token",@@ -345,7 +359,7 @@ class TestTypeformTransport:def test_typeform_source_responses_watermark_wiring(self, _name, should_use_incremental_field, last_value, expected_floor, mock_build_dependent_resource) -> None:- mock_build_dependent_resource.return_value = iter([])+ mock_build_dependent_resource.return_value.add_map.return_value = iter([])typeform_source(auth_token="token",@@ -360,6 +374,129 @@ class TestTypeformTransport:paginator = mock_build_dependent_resource.call_args.kwargs["child_endpoint_extra"]["paginator"]assert paginator._stop_when_older_than == expected_floor+ @patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.typeform.typeform.build_dependent_resource"+ )+ def test_typeform_source_responses_no_watermark_floor_when_partials_included(+ self, mock_build_dependent_resource+ ) -> None:+ mock_build_dependent_resource.return_value.add_map.return_value = iter([])++ # Drift case: partials enabled but the schema still advertises submitted_at as the cursor.+ # The submitted_at-based early stop must NOT engage — partials have no submitted_at, so a+ # whole-partial page would otherwise compare "" < watermark and halt pagination early.+ typeform_source(+ auth_token="token",+ api_base_url="https://api.typeform.com",+ endpoint="responses",+ team_id=1,+ job_id="job-1",+ should_use_incremental_field=True,+ db_incremental_field_last_value=datetime(2026, 3, 1, tzinfo=UTC),+ incremental_field="submitted_at",+ response_types="completed,partial,started",+ )++ paginator = mock_build_dependent_resource.call_args.kwargs["child_endpoint_extra"]["paginator"]+ assert paginator._stop_when_older_than is None++ @parameterized.expand(+ [+ # Completed-only: no response_type query param.+ ("completed_only", {}, None),+ # Partials: the response_type param is sent so Typeform returns partial/started responses.+ (+ "with_partials",+ {"response_types": "completed,partial,started"},+ {"response_type": "completed,partial,started"},+ ),+ ]+ )+ @patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.typeform.typeform.build_dependent_resource"+ )+ def test_typeform_source_responses_response_type_wiring(+ self,+ _name,+ extra_kwargs,+ expected_child_params_extra,+ mock_build_dependent_resource,+ ) -> None:+ mock_build_dependent_resource.return_value.add_map.return_value = iter([])++ typeform_source(+ auth_token="token",+ api_base_url="https://api.typeform.com",+ endpoint="responses",+ team_id=1,+ job_id="job-1",+ incremental_field="submitted_at",+ **extra_kwargs,+ )++ kwargs = mock_build_dependent_resource.call_args.kwargs+ assert kwargs["child_params_extra"] == expected_child_params_extra++ @parameterized.expand(+ [+ ("completed_only", "completed", "submitted_at"),+ ("with_partials", "completed,partial,started", "landed_at"),+ ]+ )+ @patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout.rest_api_resources"+ )+ def test_typeform_source_responses_partition_key(+ self, _name, response_types, expected_partition_key, mock_rest_api_resources+ ) -> None:+ mock_rest_api_resources.return_value = [+ _FakeDltResource("forms", [{"id": "form_1"}]),+ _FakeDltResource("responses", [{"token": "resp_1", "_forms_id": "form_1"}]),+ ]++ response = typeform_source(+ auth_token="token",+ api_base_url="https://api.typeform.com",+ endpoint="responses",+ team_id=1,+ job_id="job-1",+ response_types=response_types,+ )++ assert response.partition_keys == [expected_partition_key]++ @patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout.rest_api_resources"+ )+ def test_typeform_source_responses_normalizes_missing_timestamps(self, mock_rest_api_resources) -> None:+ # A partial response (no submitted_at) alongside a completed one (no landed_at).+ mock_rest_api_resources.return_value = [+ _FakeDltResource("forms", [{"id": "form_1"}]),+ _FakeDltResource(+ "responses",+ [+ {"token": "partial_1", "landed_at": "2026-03-01T00:00:00Z", "_forms_id": "form_1"},+ {"token": "completed_1", "submitted_at": "2026-03-02T00:00:00Z", "_forms_id": "form_1"},+ ],+ ),+ ]++ response = typeform_source(+ auth_token="token",+ api_base_url="https://api.typeform.com",+ endpoint="responses",+ team_id=1,+ job_id="job-1",+ response_types="completed,partial,started",+ )+ rows = list(cast(Any, response.items()))++ # Both timestamp columns must always be present so the pipeline never KeyErrors on a batch+ # whose rows all lack the configured cursor/partition field.+ assert all("submitted_at" in row and "landed_at" in row for row in rows)+ assert next(r for r in rows if r["token"] == "partial_1")["submitted_at"] is None+ assert next(r for r in rows if r["token"] == "completed_1")["landed_at"] is None+def test_typeform_source_rejects_unknown_api_base_url(self) -> None:with pytest.raises(ValueError,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform_source.pynew file mode 100644index 000000000000..3d9ba3135197--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/tests/test_typeform_source.py@@ -0,0 +1,47 @@+from posthog.schema import SourceFieldSelectConfig++from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import TypeformSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.typeform.source import TypeformSource+from products.warehouse_sources.backend.types import ExternalDataSourceType+++class TestTypeformSource:+ def setup_method(self):+ self.source = TypeformSource()+ self.team_id = 123++ def _response_types_field(self) -> SourceFieldSelectConfig:+ field = next(f for f in self.source.get_source_config.fields if f.name == "response_types")+ assert isinstance(field, SourceFieldSelectConfig)+ return field++ def test_source_type(self):+ assert self.source.source_type == ExternalDataSourceType.TYPEFORM++ def test_response_types_field_defaults_to_completed(self):+ field = self._response_types_field()+ assert field.defaultValue == "completed"+ assert [option.value for option in field.options] == ["completed", "completed,partial,started"]++ def test_response_types_field_warns_about_full_refresh(self):+ field = self._response_types_field()+ assert field.caption is not None+ assert "full refresh" in field.caption.lower()++ def test_get_schemas_completed_only_uses_submitted_at(self):+ config = TypeformSourceConfig(auth_token="token", response_types="completed")+ responses = next(s for s in self.source.get_schemas(config, self.team_id) if s.name == "responses")+ assert [f["field"] for f in responses.incremental_fields] == ["submitted_at"]++ def test_get_schemas_with_partials_is_full_refresh(self):+ config = TypeformSourceConfig(auth_token="token", response_types="completed,partial,started")+ responses = next(s for s in self.source.get_schemas(config, self.team_id) if s.name == "responses")+ # Partial/started responses have no submitted_at and share no cursor with completed ones,+ # so the all-responses mode is full-refresh only.+ assert responses.supports_incremental is False+ assert responses.incremental_fields == []++ def test_get_schemas_forms_unaffected_by_response_types(self):+ config = TypeformSourceConfig(auth_token="token", response_types="completed,partial,started")+ forms = next(s for s in self.source.get_schemas(config, self.team_id) if s.name == "forms")+ assert [f["field"] for f in forms.incremental_fields] == ["last_updated_at"]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/typeform.py b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/typeform.pyindex 03644d27fb1b..9f2007d31f4c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/typeform.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/typeform/typeform.py@@ -1,4 +1,3 @@-from collections.abc import Iterablefrom datetime import UTC, datetimefrom typing import Any, Optional, cast@@ -27,6 +26,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.typeform.settings import (ALLOWED_TYPEFORM_API_BASE_URLS,DEFAULT_TYPEFORM_API_BASE_URL,+ LANDED_AT_FIELD,+ RESPONSE_TYPE_COMPLETED_ONLY,TYPEFORM_ENDPOINTS,TypeformEndpointConfig,)@@ -266,7 +267,19 @@ def get_resource(}-def _make_source_response(endpoint_config: TypeformEndpointConfig, items_fn) -> SourceResponse:+def _ensure_response_timestamps(row: dict[str, Any]) -> dict[str, Any]:+ # Partial/started responses omit `submitted_at`; only completed ones carry it. Guarantee both+ # timestamp columns always exist (null when absent) so the pipeline's cursor/partition column+ # access never KeyErrors on an all-partial batch, whatever field the schema is configured for.+ row.setdefault("submitted_at", None)+ row.setdefault("landed_at", None)+ return row+++def _make_source_response(+ endpoint_config: TypeformEndpointConfig, items_fn, partition_key: str | None = None+) -> SourceResponse:+ partition_key = partition_key or endpoint_config.partition_keyreturn SourceResponse(name=endpoint_config.name,items=items_fn,@@ -276,9 +289,9 @@ def _make_source_response(endpoint_config: TypeformEndpointConfig, items_fn) ->sort_mode=endpoint_config.sort_mode,partition_count=1,partition_size=1,- partition_mode="datetime" if endpoint_config.partition_key else None,- partition_format="week" if endpoint_config.partition_key else None,- partition_keys=[endpoint_config.partition_key] if endpoint_config.partition_key else None,+ partition_mode="datetime" if partition_key else None,+ partition_format="week" if partition_key else None,+ partition_keys=[partition_key] if partition_key else None,)@@ -291,21 +304,34 @@ def typeform_source(should_use_incremental_field: bool = False,db_incremental_field_last_value: Optional[Any] = None,incremental_field: str | None = None,+ response_types: str = RESPONSE_TYPE_COMPLETED_ONLY,) -> SourceResponse:endpoint_config = TYPEFORM_ENDPOINTS[endpoint]base_api_url = _validated_api_base_url(api_base_url)+ # Partial/started responses have no `submitted_at`, so the all-responses mode is full-refresh+ # only (see get_schemas) and partitions on `landed_at`, present on every response type.+ include_partials = response_types != RESPONSE_TYPE_COMPLETED_ONLY++ # The watermark drives the paginator's `submitted_at`-based early stop, so it only applies to+ # completed-only incremental syncs — never when partials are included (that mode full-refreshes+ # and has no watermark), even if the schema's stored incremental field still reads+ # `submitted_at` (e.g. a not-yet-reset connection).incremental_watermark: str | None = Noneif (should_use_incremental_fieldand db_incremental_field_last_value is not None+ and not include_partialsand (incremental_field or endpoint_config.default_incremental_field) == "submitted_at"):incremental_watermark = _start_param_for_typeform(db_incremental_field_last_value)if endpoint_config.fanout:- dependent_resource = cast(- Iterable[Any],+ child_params_extra = {"response_type": response_types} if include_partials else None+ partition_key = LANDED_AT_FIELD if include_partials else None++ responses_resource = cast(+ Any,build_dependent_resource(endpoint_configs=TYPEFORM_ENDPOINTS,child_endpoint=endpoint,@@ -327,9 +353,10 @@ def typeform_source("paginator": TypeformResponsesPaginator(stop_when_older_than=incremental_watermark),"data_selector": "items",},+ child_params_extra=child_params_extra,),- )- return _make_source_response(endpoint_config, lambda: dependent_resource)+ ).add_map(_ensure_response_timestamps)+ return _make_source_response(endpoint_config, lambda: responses_resource, partition_key=partition_key)config: RESTAPIConfig = {"client": _rest_api_client_config(base_api_url, auth_token),