: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(warehouse-sources): add dovetail custom fields table (#105907)
Tom Owerse476b0197f99
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 84cb849a8021..cd4398264490 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -2602,21 +2602,21 @@ Note: Doppler publishes no OpenAPI file; the resource list was read from the doc## Dovetail — gaps-Today (8): `Contacts`, `Data`, `DocComments`, `Docs`, `Highlights`, `Projects`, `Tags`, `Users`+Today (9): `Contacts`, `Data`, `DocComments`, `Docs`, `Fields`, `Highlights`, `Projects`, `Tags`, `Users`Diffed against: <https://developers.dovetail.com/llms.txt>-- [ ] `GET /v1/insights` — insights are a first-class Dovetail object alongside docs and the main research output; entirely missing (high)-- [ ] `GET /v1/notes` — notes are a top-level content type parallel to docs and are not synced at all (high)-- [ ] `GET /v1/fields` — custom field definition lookup that resolves the field IDs carried on projects, data, and contacts (high)-- [ ] `GET /v1/insights/{insightId}/comments` — insight comments; DocComments already syncs the doc-side equivalent, leaving half the comment corpus behind (medium)+- [ ] `GET /v1/insights` — insights are a first-class Dovetail object alongside docs and the main research output; entirely missing (high) — not building: the vendor renamed insights to docs, the endpoint is marked `deprecated` and returns a `Deprecation` header, and `Docs` already syncs the same records+- [ ] `GET /v1/notes` — notes are a top-level content type parallel to docs and are not synced at all (high) — not building: the vendor renamed notes to data, and `Data` already syncs the same records+- [x] `GET /v1/fields` — custom field definition lookup that resolves the field IDs carried on projects, data, and contacts (high)+- [ ] `GET /v1/insights/{insightId}/comments` — insight comments; DocComments already syncs the doc-side equivalent, leaving half the comment corpus behind (medium) — not building: deprecated alongside the insights resource, and `DocComments` already syncs the same comments- [ ] `GET /v1/channels` — feedback channel lookup for channel-sourced data records (medium)- [ ] `GET /v1/channels/{channelId}/themes` — aggregated themes per channel — the analytical breakdown dimension over feedback (medium)- [ ] `GET /v1/folders and /v1/folders/{folderId}/contents` — folder hierarchy that organizes projects and docs (medium)- [ ] `GET /v1/channels/{channelId}/data` — channel↔data-record junction linking feedback items to their source channel (low)- [ ] `GET /v1/projects/templates` — project template lookup (low)-Note: The source already does per-doc fan-out for DocComments, so insight comments and channel sub-resources follow the same pattern. Dovetail publishes no OpenAPI file; the endpoint list came from the docs llms.txt reference index.+Note: The source already does per-doc fan-out for DocComments, so insight comments and channel sub-resources follow the same pattern. Dovetail publishes no OpenAPI file; the endpoint list came from the docs llms.txt reference index. `insights` and `notes` are the vendor's former names for `docs` and `data`: both sets of endpoints are marked deprecated or superseded in the reference and return the records the source already syncs, so they stay unbuilt rather than duplicating two tables. `/v1/fields` takes no date filter and requires `filter[field_set_type]`, so `Fields` is a full-refresh fan-out over projects that runs one pass per field set type.## Drata — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/canonical_descriptions.pyindex ebd65a018124..c3c6ee99b4ab 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/canonical_descriptions.py@@ -112,6 +112,24 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "Time at which the user was last updated, in ISO 8601 format.",},},+ "Fields": {+ "description": "A custom field definition, listed per project across every project in the "+ "workspace. Fields resolve the custom field values carried on data entries and docs, and "+ "cover both field set types ('data' and 'doc').",+ "docs_url": "https://developers.dovetail.com/reference/get_v1-fields",+ "columns": {+ "id": "Unique identifier for the field.",+ "type": "Resource type, always 'field'.",+ "label": "Display label of the field.",+ "field_type": "Data type of the field: ARR, BOOLEAN, CSAT, DATETIME, EMAIL, MULTI_SELECT, NPS, NUMBER, PERSON, PHONE, RATING, SINGLE_SELECT, TEXT, or URL.",+ "field_set_type": "Which set the field belongs to: 'data' for data entry fields, 'doc' for doc fields.",+ "project_id": "Identifier of the project the field belongs to.",+ "rank": "Ordering position of the field within its field set.",+ "options": "Choices for a select field, or display options (format, currency symbol) for a numeric field.",+ "created_at": "Time at which the field was created, in ISO 8601 format.",+ "deleted": "Whether the field has been deleted.",+ },+ },"DocComments": {"description": "A comment left on a Dovetail doc, aggregated across every doc in the workspace.","docs_url": "https://developers.dovetail.com/reference/get_v1-docs-doc-id-comments",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/dovetail.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/dovetail.pyindex 258a061a1051..eea74cf69196 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/dovetail.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/dovetail.py@@ -1,4 +1,5 @@import dataclasses+from collections.abc import Iteratorfrom datetime import UTC, date, datetimefrom typing import Any, Optional, cast@@ -161,32 +162,44 @@ def dovetail_source(resumable_source_manager.save_state(DovetailResumeConfig(paginator_state=dict(state)))if endpoint_config.fanout:- # DocComments has no server-side filter of its own, so every sync walks the full Docs- # list to discover doc ids and re-fetches comments per doc; that's inherent to the API- # (no workspace-wide comments-list endpoint exists) and mirrors other fan-out sources.- dependent_resource = build_dependent_resource(- endpoint_configs=cast(Any, DOVETAIL_ENDPOINTS),- child_endpoint=endpoint,- fanout=endpoint_config.fanout,- client_config=_client_config(api_key),- path_format_values={},- team_id=team_id,- job_id=job_id,- db_incremental_field_last_value=None,- page_size_param="page[limit]",- parent_endpoint_extra={- "paginator": _paginator_config(),- "data_selector": "data",- },- child_endpoint_extra={- "paginator": _paginator_config(),- "data_selector": "data",- },- child_params_extra={"sort": "created_at:asc"},- resume_hook=save_checkpoint,- initial_paginator_state=initial_paginator_state,- )- return _make_source_response(endpoint_config, lambda: dependent_resource)+ # Neither fan-out child has a server-side filter of its own, so every sync walks the full+ # parent list and re-fetches the child per parent; that's inherent to the API (Dovetail+ # exposes no workspace-wide comments or fields listing) and mirrors other fan-out sources.+ variants = endpoint_config.fanout_param_variants or ({},)+ # Each pass has its own paginator while the manager holds a single checkpoint, so a+ # multi-pass fan-out syncs without resume rather than resuming into the wrong pass.+ resumable = len(variants) == 1+ dependent_resources = [+ build_dependent_resource(+ endpoint_configs=cast(Any, DOVETAIL_ENDPOINTS),+ child_endpoint=endpoint,+ fanout=endpoint_config.fanout,+ client_config=_client_config(api_key),+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ db_incremental_field_last_value=None,+ page_size_param="page[limit]",+ parent_endpoint_extra={+ "paginator": _paginator_config(),+ "data_selector": "data",+ },+ child_endpoint_extra={+ "paginator": _paginator_config(),+ "data_selector": "data",+ },+ child_params_extra={"sort": "created_at:asc", **variant},+ resume_hook=save_checkpoint if resumable else None,+ initial_paginator_state=initial_paginator_state if resumable else None,+ )+ for variant in variants+ ]++ def fanout_items() -> Iterator[Any]:+ for dependent_resource in dependent_resources:+ yield from dependent_resource++ return _make_source_response(endpoint_config, fanout_items)config: RESTAPIConfig = {"client": _client_config(api_key),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/settings.pyindex f425f1af1478..c64e0b0b7004 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/settings.py@@ -1,6 +1,8 @@-from dataclasses import dataclass, field+from dataclasses import fieldfrom typing import Literal+from posthog.dataclasses import frozen+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (DependentEndpointConfig,)@@ -16,7 +18,7 @@ DOVETAIL_BASE_URL = "https://dovetail.com/api"PAGE_SIZE = 100-@dataclass+@frozenclass DovetailEndpointConfig:name: strpath: str@@ -26,6 +28,9 @@ class DovetailEndpointConfig:sort_mode: Literal["asc", "desc"] = "asc"primary_key: str | list[str] = "id"fanout: DependentEndpointConfig | None = None+ # A fan-out child whose API requires a filter with no "all" value is synced as the union of+ # one pass per value; each entry holds the extra child params for one pass.+ fanout_param_variants: tuple[dict[str, str], ...] = ()DOVETAIL_ENDPOINTS: dict[str, DovetailEndpointConfig] = {@@ -81,6 +86,28 @@ DOVETAIL_ENDPOINTS: dict[str, DovetailEndpointConfig] = {parent_field_renames={"id": "doc_id"},),),+ "Fields": DovetailEndpointConfig(+ name="Fields",+ # `/v1/fields` requires `filter[project_id]` (or a workspace field group id) alongside+ # `filter[field_set_type]`. The framework binds a resolved param in the path only, so the+ # project filter rides in the path and the field set type is a per-pass child param.+ path="/v1/fields?filter[project_id]={project_id}",+ # The endpoint offers no date filter, only `project_id` / `workspace_field_group_id` /+ # `field_set_type`, so this table is full refresh. A workspace field group's fields are+ # listed under every project the group is linked to, so the project is part of the key.+ primary_key=["project_id", "id"],+ fanout=DependentEndpointConfig(+ parent_name="Projects",+ resolve_param="project_id",+ resolve_field="id",+ # Field rows already carry `project_id`, so nothing needs injecting from the parent.+ include_from_parent=[],+ ),+ fanout_param_variants=(+ {"filter[field_set_type]": "data"},+ {"filter[field_set_type]": "doc"},+ ),+ ),}ENDPOINTS = tuple(DOVETAIL_ENDPOINTS)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/tests/test_dovetail.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/tests/test_dovetail.pyindex 51da2f50a982..1abe7b297c0d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/tests/test_dovetail.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dovetail/tests/test_dovetail.py@@ -297,3 +297,74 @@ class TestDovetailSourceFanout:{"id": "c2", "body": "world", "doc_id": "doc2"},]assert response.primary_keys == ["doc_id", "id"]++ def _mock_fields_fanout(self, requests_mock: Any) -> None:+ requests_mock.get(+ f"{BASE_URL}/v1/projects",+ json={+ "data": [{"id": "p1"}, {"id": "p2"}],+ "page": {"total_count": 2, "has_more": False, "next_cursor": None},+ },+ )++ def fields_response(request: Any, context: Any) -> dict[str, Any]:+ project_id = request.qs["filter[project_id]"][0]+ field_set_type = request.qs["filter[field_set_type]"][0]+ return {+ "data": [+ {+ "id": f"f-{project_id}-{field_set_type}",+ "project_id": project_id,+ "field_set_type": field_set_type,+ }+ ],+ "page": {"total_count": 1, "has_more": False, "next_cursor": None},+ }++ requests_mock.get(f"{BASE_URL}/v1/fields", json=fields_response)++ def test_fields_fans_out_over_every_project_and_field_set_type(self, requests_mock: Any) -> None:+ self._mock_fields_fanout(requests_mock)++ response = dovetail_source(+ api_key="tok",+ endpoint="Fields",+ team_id=1,+ job_id="job-1",+ resumable_source_manager=_FakeResumeManager(),+ )+ rows = _collect_rows(response)++ assert rows == [+ {"id": "f-p1-data", "project_id": "p1", "field_set_type": "data"},+ {"id": "f-p2-data", "project_id": "p2", "field_set_type": "data"},+ {"id": "f-p1-doc", "project_id": "p1", "field_set_type": "doc"},+ {"id": "f-p2-doc", "project_id": "p2", "field_set_type": "doc"},+ ]+ assert response.primary_keys == ["project_id", "id"]++ field_requests = [r for r in requests_mock.request_history if r.path == "/api/v1/fields"]+ assert [(r.qs["filter[project_id]"][0], r.qs["filter[field_set_type]"][0]) for r in field_requests] == [+ ("p1", "data"),+ ("p2", "data"),+ ("p1", "doc"),+ ("p2", "doc"),+ ]+ assert field_requests[0].qs["page[limit]"] == ["100"]++ def test_fields_multi_pass_fanout_saves_no_checkpoint(self, requests_mock: Any) -> None:+ self._mock_fields_fanout(requests_mock)+ manager = _FakeResumeManager()++ response = dovetail_source(+ api_key="tok",+ endpoint="Fields",+ team_id=1,+ job_id="job-1",+ resumable_source_manager=manager,+ )+ _collect_rows(response)++ # The manager holds one checkpoint and each pass paginates independently, so resuming+ # would restart in the wrong pass; the passes are cheap enough to redo instead.+ assert manager.saved == []