: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): add 1 missing table to the Sprig source (#118321)
Tom Owerscff4875f866a
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 51c9ceeee4af..7a7d9044e10f 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -1086,7 +1086,6 @@1 products/warehouse_sources/backend/temporal/data_imports/sources/spot_io/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/spot_io/spot_io.py1 products/warehouse_sources/backend/temporal/data_imports/sources/spotlercrm/spotlercrm.py-1 products/warehouse_sources/backend/temporal/data_imports/sources/sprig/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/sprig/sprig.py1 products/warehouse_sources/backend/temporal/data_imports/sources/squadcast/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/squadcast/squadcast.pydiff --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 d680c14071af..911af7c872f3 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@@ -11525,7 +11525,7 @@ Today (2): `Responses`, `Surveys`Diffed against: <https://docs.sprig.com/reference/sprig-api/overview>-- [ ] `GET /v1/themes (Retrieve Themes)` — Sprig's AI-clustered themes over open-text answers - the breakdown dimension for the Responses table we already sync (high)+- [x] `GET /v1/themes (Retrieve Themes)` — Sprig's AI-clustered themes over open-text answers - the breakdown dimension for the Responses table we already sync (high)Note: Sprig's public read surface is genuinely tiny: GET /v1/surveys, GET /v1/responses, GET /v1/themes, plus GET /v2/users/{userId}. The users endpoint only fetches a single record by id (no list), so it is not syncable as a warehouse table; the remaining v2 endpoints are writes (Upsert a User, Purge Visitors). Two tables is therefore close to full coverage once themes is added.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/canonical_descriptions.pyindex 302f5e568e8d..a2c67f44d682 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/canonical_descriptions.py@@ -48,4 +48,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"deletedAt": "When the response was deleted, only returned when `with_deleted_responses` is true.",},},+ "Themes": {+ "description": "AI-generated themes over open-text survey answers. Each row links one answer "+ "to one theme; an answer can belong to several themes.",+ "docs_url": "https://docs.sprig.com/reference/sprig-api/v1/get-v1-themes-1",+ "columns": {+ "id": "Sprig-assigned identifier for the themed response.",+ "visitorId": "Sprig-assigned identifier for the visitor who answered.",+ "surveyId": "The id of the survey this answer belongs to.",+ "questionId": "The id of the question this answer is for.",+ "questionText": "The text of the question as shown to the visitor.",+ "questionType": "The type of question (e.g. OPEN).",+ "response": "The visitor's open-text answer.",+ "responseGroupUid": "Identifier grouping every answer from a single response submission.",+ "theme": "The name of the theme the answer is associated with.",+ "themeDescription": "A description of the theme.",+ "createdAt": "The date and time the answer was created.",+ "updatedAt": "The date and time the answer was last updated.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/settings.pyindex 8fd934087247..5461179186ae 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/settings.py@@ -17,7 +17,7 @@ def _datetime_field(name: str) -> IncrementalField:}-@dataclass+@dataclass(frozen=True)class SprigEndpointConfig:name: strpath: str@@ -26,11 +26,14 @@ class SprigEndpointConfig:# Stable creation-date field to partition by and to filter incrementally via the# `start` query param (milliseconds since epoch). Never a mutable field.partition_key: str | None = "createdAt"+ # `None` for endpoints whose spec takes no `limit` param.+ page_size: int | None = DEFAULT_PAGE_SIZE+ supports_incremental: bool = True-# Both list endpoints return `{"data": [...], "cursor": "<base64>"|null}`, are cursor-paginated-# up to 1000 items per page, and accept `start`/`end` query params (creation date, ms since-# epoch) for a created-since time window. Neither endpoint exposes an `updated_since` filter, so+# The list endpoints return `{"data": [...], "cursor": "<base64>"|null}`, are cursor-paginated+# (Surveys and Responses take a `limit` of up to 1000), and accept `start`/`end` query params+# (creation date, ms since epoch) for a created-since time window. No endpoint exposes an `updated_since` filter, so# edited/deleted responses do not re-surface via incremental sync.SPRIG_ENDPOINTS: dict[str, SprigEndpointConfig] = {"Surveys": SprigEndpointConfig(@@ -47,11 +50,22 @@ SPRIG_ENDPOINTS: dict[str, SprigEndpointConfig] = {table_name="responses",primary_keys=["responseGroupUid", "questionId"],),+ "Themes": SprigEndpointConfig(+ name="Themes",+ path="/v1/themes",+ # Each row links one open-text answer to one AI-generated theme, and an answer can carry+ # several themes. Sprig regenerates themes over time, and `start` filters on theme+ # generation rather than the row's `createdAt`, so incremental merge would keep stale+ # theme assignments. Full refresh only.+ table_name="themes",+ primary_keys=["responseGroupUid", "questionId", "theme"],+ page_size=None,+ supports_incremental=False,+ ),}ENDPOINTS = tuple(SPRIG_ENDPOINTS.keys())-# Both endpoints support incremental sync on their creation timestamp via the `start` param.INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {- name: [_datetime_field("createdAt")] for name in SPRIG_ENDPOINTS+ name: [_datetime_field("createdAt")] if cfg.supports_incremental else [] for name, cfg in SPRIG_ENDPOINTS.items()}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/sprig.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/sprig.pyindex f2a5dd578338..0b5710a37ad3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/sprig.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/sprig.py@@ -17,7 +17,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.sprig.settings import (- DEFAULT_PAGE_SIZE,SPRIG_API_BASE_URL,SPRIG_ENDPOINTS,)@@ -73,17 +72,18 @@ def _incremental_param_config(incremental_field: str) -> dict[str, Any]:def get_resource(name: str, should_use_incremental_field: bool) -> EndpointResource:cfg = SPRIG_ENDPOINTS[name]+ incremental = should_use_incremental_field and cfg.supports_incremental- params: dict[str, Any] = {"limit": DEFAULT_PAGE_SIZE}- if should_use_incremental_field:+ params: dict[str, Any] = {}+ if cfg.page_size is not None:+ params["limit"] = cfg.page_size+ if incremental:params["start"] = _incremental_param_config("createdAt")return {"name": cfg.name,"table_name": cfg.table_name,- "write_disposition": {"disposition": "merge", "strategy": "upsert"}- if should_use_incremental_field- else "replace",+ "write_disposition": {"disposition": "merge", "strategy": "upsert"} if incremental else "replace","endpoint": {"data_selector": "data","path": cfg.path,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/tests/test_sprig.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/tests/test_sprig.pyindex 68977c65dd37..8aaa479659b8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/tests/test_sprig.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sprig/tests/test_sprig.py@@ -70,8 +70,15 @@ class TestGetResource:endpoint = cast(dict[str, Any], resource["endpoint"])return cast(dict[str, Any], endpoint["params"])- @parameterized.expand(list(ENDPOINTS))- def test_resource_shape(self, endpoint: str) -> None:+ @parameterized.expand(+ [+ ("Surveys", 1000),+ ("Responses", 1000),+ # The themes spec takes no `limit` param.+ ("Themes", None),+ ]+ )+ def test_resource_shape(self, endpoint: str, expected_limit: int | None) -> None:cfg = SPRIG_ENDPOINTS[endpoint]resource = get_resource(endpoint, should_use_incremental_field=False)endpoint_config = cast(dict[str, Any], resource["endpoint"])@@ -82,11 +89,11 @@ class TestGetResource:assert resource["table_format"] == "delta"assert endpoint_config["path"] == cfg.pathassert endpoint_config["data_selector"] == "data"- assert params["limit"] == 1000+ assert params.get("limit") == expected_limitassert "start" not in paramsassert resource["write_disposition"] == "replace"- @parameterized.expand(list(ENDPOINTS))+ @parameterized.expand([name for name in ENDPOINTS if SPRIG_ENDPOINTS[name].supports_incremental])def test_incremental_resource_sets_filter_and_merges(self, endpoint: str) -> None:resource = get_resource(endpoint, should_use_incremental_field=True)@@ -96,6 +103,12 @@ class TestGetResource:assert param["cursor_path"] == "createdAt"assert param["convert"] is _format_incremental_value+ def test_full_refresh_only_endpoint_ignores_incremental_flag(self) -> None:+ resource = get_resource("Themes", should_use_incremental_field=True)++ assert resource["write_disposition"] == "replace"+ assert "start" not in self._params(resource)+class TestSprigCursorPaginator:def _paginator(self) -> JSONResponseCursorPaginator:@@ -120,15 +133,20 @@ class TestSprigSource:assert result.requests[0].param("cursor") == "saved-cursor"- def test_resume_hook_saves_state_after_batch(self) -> None:+ @parameterized.expand([("Surveys", "/v1/surveys", "1000"), ("Themes", "/v1/themes", None)])+ def test_resume_hook_saves_state_after_batch(self, endpoint: str, path: str, limit: str | None) -> None:result = _run([ScriptedResponse(json={"data": [{"id": 1}], "cursor": "next-1"}),ScriptedResponse(json={"data": [{"id": 2}], "cursor": None}),- ]+ ],+ endpoint=endpoint,)+ assert result.paths == [path, path]+ assert result.params("limit") == [limit, limit]assert result.params("cursor") == [None, "next-1"]+ assert result.rows == [{"id": 1}, {"id": 2}]# The terminal page has no cursor, so nothing is saved for it.assert result.saved_states == [SprigResumeConfig(next_cursor="next-1")]