: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): support Profound API version v2 (#86331)
Tom Owersc41cc9365e7f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/source.pyindex 440bf08604e6..facb7d6b4e0b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/source.py@@ -38,8 +38,13 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass ProfoundSource(ResumableSource[ProfoundSourceConfig, ProfoundResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docs- # There is no version to select: `v1` on the organization lists and `v2` on the reports are- # per-resource path segments, not a version a caller can pin. The framework default applies.+ # Profound versions purely by URL path segment (`/v1/...`, `/v2/...`) — no version header or+ # account setting. The source already reads the newer v2 report surface (`/v2/reports/*`)+ # alongside the org lists that only exist under `/v1/`, so the label is a pin recorded on the+ # source, not a request-layer branch: every version resolves to the same requests (see+ # settings.py). v2 is the default so new sources record the surface they actually sync.+ supported_versions = ("v1", "v2")+ default_version = "v2"api_docs_url = "https://docs.tryprofound.com/rest-api/introduction"@propertydiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound_source.pyindex d391ccc95fdf..b5ded3591803 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound_source.py@@ -1,8 +1,12 @@-from typing import Any+import json+from collections.abc import Iterable+from typing import Any, cast+from urllib.parse import urlparsefrom unittest import mockfrom parameterized import parameterized+from requests import Responsefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs@@ -11,6 +15,28 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.profound.sfrom products.warehouse_sources.backend.types import ExternalDataSourceTypeSOURCE_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.profound.source"+PROFOUND_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.profound.profound"+CLIENT_SESSION_PATCH = "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.make_tracked_session"+++def _capture_paths(mock_session: mock.MagicMock, body: Any) -> list[str]:+ """Wire a mock REST session that returns `body` and records each request's URL path."""+ session = mock_session.return_value+ session.headers = {}+ paths: list[str] = []++ def _prepare(request: Any) -> mock.MagicMock:+ paths.append(urlparse(request.url).path)+ prepared = mock.MagicMock()+ prepared.url = request.url+ return prepared++ session.prepare_request.side_effect = _prepare+ page = Response()+ page.status_code = 200+ page._content = json.dumps(body).encode()+ session.send.return_value = page+ return pathsclass _Config:@@ -112,6 +138,47 @@ class TestProfoundSource:assert mock_source.call_args.kwargs["db_incremental_field_last_value"] is None+ def test_version_declaration_defaults_to_v2_with_v1_supported(self) -> None:+ # Profound versions by URL path segment, so both labels resolve to the same requests;+ # the default tracks the newest label without deprecating the old one.+ source = ProfoundSource()++ assert source.supported_versions == ("v1", "v2")+ assert source.default_version == "v2"+ assert source.deprecated_versions == ()++ @parameterized.expand([("unpinned", None), ("pinned_v1", "v1"), ("pinned_v2", "v2")])+ @mock.patch(f"{PROFOUND_MODULE}.fetch_category_ids", return_value=["c1"])+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_report_path_is_fixed_regardless_of_pin(+ self, _name: str, pinned: str | None, MockSession, _mock_categories+ ) -> None:+ # The version is never sent on the wire — a v1 pin (existing sources) and the v2 default+ # both POST to the same `/v2/reports/...` route. This guards the byte-for-byte promise.+ paths = _capture_paths(MockSession, {"info": {"next_cursor": None}, "data": []})+ inputs = _inputs(schema_name="Visibility", api_version=pinned)+ manager = mock.MagicMock()+ manager.can_resume.return_value = False++ response = ProfoundSource().source_for_pipeline(_Config(), manager, inputs) # type: ignore[arg-type]+ list(cast(Iterable[Any], response.items()))++ assert paths and paths[0] == "/v2/reports/visibility"++ @parameterized.expand([("unpinned", None), ("pinned_v1", "v1"), ("pinned_v2", "v2")])+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_reference_path_is_fixed_regardless_of_pin(self, _name: str, pinned: str | None, MockSession) -> None:+ # The org lists only exist under `/v1/`, and no pin moves them.+ paths = _capture_paths(MockSession, [{"id": "1"}])+ inputs = _inputs(schema_name="Categories", api_version=pinned)+ manager = mock.MagicMock()+ manager.can_resume.return_value = False++ response = ProfoundSource().source_for_pipeline(_Config(), manager, inputs) # type: ignore[arg-type]+ list(cast(Iterable[Any], response.items()))++ assert paths and paths[0] == "/v1/org/categories"+def test_source_is_visible_and_labelled_alpha(self) -> None:# unreleasedSource=True hides the connector from users entirely; this source is finished.config = ProfoundSource().get_source_config