: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 Hubspot API version 2026-03 (#71669)
Tom Owers4e2d7861e084
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/helpers.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/helpers.pyindex 1ab57115f357..ec9b67e1edf9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/helpers.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/helpers.py@@ -12,7 +12,7 @@ from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom .auth import HubspotRetryableError, hubspot_refresh_access_token-from .settings import OBJECT_TYPE_PLURAL+from .settings import OBJECT_TYPE_PLURAL, apply_crm_api_versionBASE_URL = "https://api.hubapi.com/"@@ -210,7 +210,16 @@ def fetch_data(_data = None-def _get_property_names(api_key: str, refresh_token: str, object_type: str, source_id: str | None = None) -> list[str]:+def _get_property_names(+ api_key: str,+ refresh_token: str,+ object_type: str,+ source_id: str | None = None,+ *,+ # Required (no default) so a caller can't silently downgrade a pinned source to v3 by+ # forgetting to thread the resolved version — this function builds a CRM URL.+ api_version: str,+) -> list[str]:"""Retrieve property names for a given entity from the HubSpot API.@@ -224,7 +233,7 @@ def _get_property_names(api_key: str, refresh_token: str, object_type: str, sourException: If an error occurs during the API request."""properties = []- endpoint = f"/crm/v3/properties/{OBJECT_TYPE_PLURAL[object_type]}"+ endpoint = apply_crm_api_version(f"/crm/v3/properties/{OBJECT_TYPE_PLURAL[object_type]}", api_version)for page in fetch_data(endpoint, api_key, refresh_token, source_id=source_id):properties.extend([prop["name"] for prop in page])diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/hubspot.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/hubspot.pyindex 6d4bc094c25f..8d21745368d7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/hubspot.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/hubspot.py@@ -41,12 +41,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hefrom products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import (ASSOCIATIONS_BATCH_SIZE,DEFAULT_PROPS,+ HUBSPOT_API_VERSION_V3,HUBSPOT_ENDPOINTS,OBJECT_TYPE_SINGULAR,SEARCH_PAGE_SIZE,SEARCH_RESULT_CAP,SEARCH_WINDOW_DAYS,STARTDATE,+ apply_crm_api_version,)PROPERTY_LENGTH_LIMIT = 16_000 # Empirically determined rough limit for the HubSpot API@@ -79,11 +81,14 @@ def _get_properties_str(logger: FilteringBoundLogger,include_custom_props: bool = True,source_id: str | None = None,+ api_version: str = HUBSPOT_API_VERSION_V3,) -> str:"""Builds a comma-separated string of properties to request from the HubSpot API (GET path)."""props = list(props)if include_custom_props:- all_props = _get_property_names(api_key, refresh_token, object_type, source_id=source_id)+ all_props = _get_property_names(+ api_key, refresh_token, object_type, source_id=source_id, api_version=api_version+ )custom_props = [prop for prop in all_props if not prop.startswith("hs_")]props = props + [c for c in custom_props if c not in props]@@ -114,6 +119,7 @@ def _resolve_search_properties(required_props: Sequence[str],logger: FilteringBoundLogger,source_id: str | None,+ api_version: str = HUBSPOT_API_VERSION_V3,) -> tuple[list[str], list[str]]:"""Resolve the properties list for the search body.@@ -127,7 +133,9 @@ def _resolve_search_properties(with thousands of custom properties can otherwise blow up CPU/memory at scale)."""if selected_properties:- available_props = set(_get_property_names(api_key, refresh_token, object_type, source_id=source_id))+ available_props = set(+ _get_property_names(api_key, refresh_token, object_type, source_id=source_id, api_version=api_version)+ )invalid_props = [p for p in selected_properties if p not in available_props]if invalid_props:logger.warning(@@ -145,7 +153,9 @@ def _resolve_search_properties(else:props = list(DEFAULT_PROPS[endpoint])if include_custom_props:- all_props = _get_property_names(api_key, refresh_token, object_type, source_id=source_id)+ all_props = _get_property_names(+ api_key, refresh_token, object_type, source_id=source_id, api_version=api_version+ )custom = [p for p in all_props if not p.startswith("hs_") and p not in props]props.extend(custom)@@ -247,6 +257,10 @@ def get_rows(include_custom_props: bool = True,selected_properties: list[str] | None = None,source_id: str | None = None,+ *,+ # Required (no default) so a caller can't silently downgrade a pinned source to v3 by+ # forgetting to thread the resolved version — this function builds a CRM URL.+ api_version: str,) -> Iterator[Any]:"""Full-refresh (and seed-incremental) fetch via the paginated GET endpoint."""config = HUBSPOT_ENDPOINTS[endpoint]@@ -260,7 +274,9 @@ def get_rows(if selected_properties:# Validate selected properties against what HubSpot actually has- available_props = set(_get_property_names(api_key, refresh_token, object_type, source_id=source_id))+ available_props = set(+ _get_property_names(api_key, refresh_token, object_type, source_id=source_id, api_version=api_version)+ )invalid_props = [p for p in selected_properties if p not in available_props]if invalid_props:logger.warning(@@ -284,6 +300,7 @@ def get_rows(include_custom_props=False,logger=logger,source_id=source_id,+ api_version=api_version,)else:props_str = _get_properties_str(@@ -294,6 +311,7 @@ def get_rows(include_custom_props=include_custom_props,logger=logger,source_id=source_id,+ api_version=api_version,)expected_properties = props_str.split(",") if props_str else []@@ -308,7 +326,7 @@ def get_rows(logger.debug(f"Hubspot: resuming from URL: {url}")else:url = _build_initial_url(- path=config.path,+ path=apply_crm_api_version(config.path, api_version),associations=config.associations,properties=props_str,)@@ -387,6 +405,10 @@ def _batch_read_associations(refresh_token: str,source_id: str | None,logger: FilteringBoundLogger,+ *,+ # Required (no default) so a caller can't silently downgrade a pinned source to v3 by+ # forgetting to thread the resolved version — this function builds a CRM URL.+ api_version: str,) -> dict[str, list[dict[str, Any]]]:"""POST /crm/v4/associations/{from}/{to}/batch/read in chunks of ASSOCIATIONS_BATCH_SIZE.@@ -396,7 +418,10 @@ def _batch_read_associations(if not ids:return {}- url = urllib.parse.urljoin(BASE_URL, f"/crm/v4/associations/{from_entity_plural}/{to_entity_plural}/batch/read")+ url = urllib.parse.urljoin(+ BASE_URL,+ apply_crm_api_version(f"/crm/v4/associations/{from_entity_plural}/{to_entity_plural}/batch/read", api_version),+ )by_from: dict[str, list[dict[str, Any]]] = {}@retry(@@ -473,6 +498,7 @@ def _backfill_associations_into_results(refresh_token: str,source_id: str | None,logger: FilteringBoundLogger,+ api_version: str = HUBSPOT_API_VERSION_V3,) -> None:"""Hydrate `result["associations"]` for each search result so _flatten_result handles it uniformly."""if not association_types or not results:@@ -489,6 +515,7 @@ def _backfill_associations_into_results(refresh_token=refresh_token,source_id=source_id,logger=logger,+ api_version=api_version,)for r in results:tos = mapping.get(str(r.get("id", "")), [])@@ -507,6 +534,10 @@ def get_rows_via_search(selected_properties: list[str] | None = None,source_id: str | None = None,now_ms: Optional[int] = None,+ *,+ # Required (no default) so a caller can't silently downgrade a pinned source to v3 by+ # forgetting to thread the resolved version — this function builds CRM URLs.+ api_version: str,) -> Iterator[Any]:"""Incremental fetch via POST /crm/v3/objects/{entity}/search.@@ -535,10 +566,11 @@ def get_rows_via_search(required_props=[cursor_prop, "hs_object_id"],logger=logger,source_id=source_id,+ api_version=api_version,)headers = _get_headers(api_key)- search_url = urllib.parse.urljoin(BASE_URL, f"{config.path}/search")+ search_url = urllib.parse.urljoin(BASE_URL, f"{apply_crm_api_version(config.path, api_version)}/search")batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)resume_config = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None@@ -645,6 +677,7 @@ def get_rows_via_search(refresh_token=refresh_token,source_id=source_id,logger=logger,+ api_version=api_version,)for result in results:@@ -718,6 +751,11 @@ def hubspot_source(source_id: str | None = None,db_incremental_field_last_value: Any = None,use_search_path: bool = False,+ *,+ # Required (no default) so a cross-module caller can't silently downgrade a pinned+ # source to the legacy version by forgetting to thread it. Internal request helpers+ # keep the legacy default; they're only reached through this guarded entry point.+ api_version: str,) -> SourceResponse:"""Build a SourceResponse for the pipeline.@@ -743,6 +781,7 @@ def hubspot_source(include_custom_props=include_custom_props,selected_properties=selected_properties,source_id=source_id,+ api_version=api_version,)else:items = lambda: get_rows(@@ -754,6 +793,7 @@ def hubspot_source(include_custom_props=include_custom_props,selected_properties=selected_properties,source_id=source_id,+ api_version=api_version,)return SourceResponse(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/settings.pyindex fd29ba45a1c0..201e87a777dd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/settings.py@@ -1,5 +1,6 @@"""Hubspot source settings and constants"""+import refrom dataclasses import dataclass, fieldfrom datetime import datetimefrom typing import Optional@@ -8,6 +9,30 @@ from products.warehouse_sources.backend.types import IncrementalField, IncrementSTARTDATE = datetime(year=2000, month=1, day=1)+# Vendor API version labels. HubSpot moved to date-based versioning ("YYYY-MM"); the legacy+# "v3" pin keeps the historical /crm/v3/ (objects, properties) + /crm/v4/ (association+# batch-read) URL split. Under a date version the version segment moves to *after* the API+# resource name, so /crm/v3/objects/... becomes /crm/objects/2026-03/... and+# /crm/v4/associations/... becomes /crm/associations/2026-03/... .+HUBSPOT_API_VERSION_V3 = "v3"+HUBSPOT_API_VERSION_2026_03 = "2026-03"++# Matches the leading "/crm/<v3|v4>/<resource>/" of a CRM path, capturing the resource name+# (objects, properties, associations) so the version can be re-inserted after it.+_CRM_VERSION_SEGMENT = re.compile(r"^/crm/v[34]/([^/]+)/")+++def apply_crm_api_version(path: str, api_version: str) -> str:+ """Rewrite a HubSpot CRM path to the pinned vendor API version. The legacy "v3" pin is+ returned unchanged so existing syncs are byte-for-byte unaffected. For a date version the+ version segment moves behind the resource name, e.g. /crm/v3/objects/contacts ->+ /crm/objects/2026-03/contacts and /crm/v4/associations/a/b/batch/read ->+ /crm/associations/2026-03/a/b/batch/read."""+ if api_version == HUBSPOT_API_VERSION_V3:+ return path+ return _CRM_VERSION_SEGMENT.sub(rf"/crm/\1/{api_version}/", path)++CONTACT = "contact"COMPANY = "company"DEAL = "deal"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.pyindex f199ea3c9116..63c87bbf6b61 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py@@ -35,6 +35,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hufrom products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import (DEFAULT_PROPS,ENDPOINTS as HUBSPOT_ENDPOINTS,+ HUBSPOT_API_VERSION_2026_03,+ HUBSPOT_API_VERSION_V3,HUBSPOT_ENDPOINTS as HUBSPOT_ENDPOINT_CONFIGS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -48,9 +50,12 @@ class HubspotSourceOldConfig(config.Config):@SourceRegistry.registerclass HubspotSource(ResumableSource[HubspotSourceConfig | HubspotSourceOldConfig, HubspotResumeConfig], OAuthMixin):- supported_versions = ("v3",)- default_version = "v3"- api_docs_url = "https://developers.hubspot.com/docs"+ supported_versions = (HUBSPOT_API_VERSION_V3, HUBSPOT_API_VERSION_2026_03)+ # 2026-03 is available for opt-in, but new sources stay on v3 until the date-versioned+ # objects/search/association-batch-read paths are confirmed against the live HubSpot API.+ # Flip the default once a real 2026-03 sync has been verified end to end.+ default_version = HUBSPOT_API_VERSION_V3+ api_docs_url = "https://developers.hubspot.com/docs/api-reference/latest/overview"lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@@ -210,6 +215,7 @@ class HubspotSource(ResumableSource[HubspotSourceConfig | HubspotSourceOldConfigsource_id=inputs.source_id,db_incremental_field_last_value=inputs.db_incremental_field_last_value,use_search_path=use_search_path,+ api_version=self.resolve_api_version(inputs.api_version),)def _should_use_search_path(self, inputs: SourceInputs) -> bool:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_helpers.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_helpers.pyindex 01ed678d539a..0ea6d221dd59 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_helpers.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_helpers.py@@ -11,6 +11,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.he_is_retryable_status,fetch_data,)+from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import HUBSPOT_API_VERSION_V3def _make_response(status: int, payload: dict[str, Any] | None = None) -> MagicMock:@@ -123,7 +124,7 @@ def test_get_property_names_recovers_from_transient_477() -> None:good = _make_response(200, {"results": [{"name": "deal_stage"}, {"name": "amount"}]})ctx, captured = _patch_session([_make_response(477), good])with ctx:- names = _get_property_names("key", "refresh", "deal")+ names = _get_property_names("key", "refresh", "deal", api_version=HUBSPOT_API_VERSION_V3)assert names == ["deal_stage", "amount"]assert len(captured) == 2diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_search.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_search.pyindex 992307ef492e..9e81fbd073b6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_search.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_hubspot_search.py@@ -19,6 +19,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.huhubspot_source,)from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import (+ HUBSPOT_API_VERSION_2026_03,+ HUBSPOT_API_VERSION_V3,HUBSPOT_ENDPOINTS,SEARCH_PAGE_SIZE,SEARCH_RESULT_CAP,@@ -185,6 +187,29 @@ class TestResolveSearchProperties:assert props.count("hs_lastmodifieddate") == 1assert props.count("hs_object_id") == 1+ def test_default_props_discover_custom_and_thread_version(self) -> None:+ # include_custom_props=True with no selection: non-hs_ custom props are appended,+ # and the pinned api_version reaches the property-discovery call.+ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hubspot._get_property_names",+ return_value=["amount", "hs_internal_only", "custom_field"],+ ) as get_names_mock:+ props, _ = _resolve_search_properties(+ api_key="k",+ refresh_token="r",+ endpoint="deals",+ object_type="deal",+ selected_properties=None,+ include_custom_props=True,+ required_props=["hs_lastmodifieddate", "hs_object_id"],+ logger=MagicMock(),+ source_id=None,+ api_version=HUBSPOT_API_VERSION_2026_03,+ )+ assert "custom_field" in props # non-hs_ custom prop discovered and appended+ assert "hs_internal_only" not in props # hs_ props are not auto-added+ assert get_names_mock.call_args.kwargs["api_version"] == HUBSPOT_API_VERSION_2026_03+def test_invalid_selected_ignored(self) -> None:logger = MagicMock()with patch(@@ -217,6 +242,7 @@ class TestBatchReadAssociations:refresh_token="r",source_id=None,logger=MagicMock(),+ api_version=HUBSPOT_API_VERSION_V3,)assert result == {}@@ -242,12 +268,44 @@ class TestBatchReadAssociations:refresh_token="r",source_id=None,logger=MagicMock(),+ api_version=HUBSPOT_API_VERSION_V3,)assert calls[0]["url"].endswith("/crm/v4/associations/contacts/deals/batch/read")assert calls[0]["json"] == {"inputs": [{"id": "1"}, {"id": "2"}, {"id": "3"}]}assert result["1"] == [{"id": "9", "type": "x"}]+ @pytest.mark.parametrize(+ "api_version,expected_suffix",+ [+ (HUBSPOT_API_VERSION_V3, "/crm/v4/associations/contacts/deals/batch/read"),+ (HUBSPOT_API_VERSION_2026_03, "/crm/associations/2026-03/contacts/deals/batch/read"),+ ],+ )+ def test_url_carries_pinned_api_version(self, api_version: str, expected_suffix: str) -> None:+ calls = []++ def _post(url, headers=None, json=None, timeout=None): # noqa: ARG001+ calls.append({"url": url})+ return _make_response(200, {"results": []})++ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hubspot.make_tracked_session",+ new=lambda *_a, **_k: type("_S", (), {"post": staticmethod(_post)})(),+ ):+ _batch_read_associations(+ from_entity_plural="contacts",+ to_entity_plural="deals",+ ids=["1"],+ headers={"authorization": "Bearer x"},+ refresh_token="r",+ source_id=None,+ logger=MagicMock(),+ api_version=api_version,+ )++ assert calls[0]["url"].endswith(expected_suffix)+def test_splits_into_chunks_of_batch_size(self) -> None:posts = []@@ -272,6 +330,7 @@ class TestBatchReadAssociations:refresh_token="r",source_id=None,logger=MagicMock(),+ api_version=HUBSPOT_API_VERSION_V3,)assert len(posts) == 3@@ -293,6 +352,7 @@ class TestBatchReadAssociations:refresh_token="r",source_id=None,logger=MagicMock(),+ api_version=HUBSPOT_API_VERSION_V3,)assert result == {}@@ -388,6 +448,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -426,6 +487,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=seed_iso,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -463,6 +525,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value="2024-01-01T00:00:00.000Z", # ignored on resumeinclude_custom_props=False,now_ms=_FIXED_NOW_MS + 999_999_999, # ignored on resume (sync_end_ms from state wins)+ api_version=HUBSPOT_API_VERSION_V3,))@@ -470,6 +533,38 @@ class TestGetRowsViaSearch:assert int(body["filterGroups"][0]["filters"][0]["value"]) == last + 1 # last_cursor_ms + 1assert int(body["filterGroups"][0]["filters"][1]["value"]) == end # sync_end_ms from state, not now_ms+ @pytest.mark.parametrize(+ "api_version,expected_suffix",+ [+ (HUBSPOT_API_VERSION_V3, "/crm/v3/objects/deals/search"),+ (HUBSPOT_API_VERSION_2026_03, "/crm/objects/2026-03/deals/search"),+ ],+ )+ def test_search_url_carries_pinned_api_version(self, api_version: str, expected_suffix: str) -> None:+ manager = _make_manager()+ logger = MagicMock()+ side_effect, captured = _setup_search_post([_make_response(200, _search_page([]))])++ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hubspot.make_tracked_session",+ new=lambda *_a, **_k: type("_S", (), {"post": staticmethod(side_effect)})(),+ ):+ list(+ get_rows_via_search(+ api_key="k",+ refresh_token="r",+ endpoint="deals",+ logger=logger,+ resumable_source_manager=manager,+ db_incremental_field_last_value=_RECENT_SEED_ISO,+ include_custom_props=False,+ now_ms=_FIXED_NOW_MS,+ api_version=api_version,+ )+ )++ assert captured[0]["url"].endswith(expected_suffix)+def test_ignores_next_url_resume_state(self) -> None:# A stale next_url from the GET path should not leak into the search path.resume = HubspotResumeConfig(next_url="https://stale.example/get")@@ -491,6 +586,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -531,6 +627,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=sync_start_iso,include_custom_props=False,now_ms=sync_end,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -563,6 +660,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -606,6 +704,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -650,6 +749,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=str(identical_cursor - 1),include_custom_props=False,now_ms=identical_cursor + 1_000,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -684,6 +784,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=sync_start_iso,include_custom_props=False,now_ms=sync_end,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -722,6 +823,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -760,6 +862,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -795,6 +898,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -825,6 +929,7 @@ class TestGetRowsViaSearch:db_incremental_field_last_value=_RECENT_SEED_ISO,include_custom_props=False,now_ms=_FIXED_NOW_MS,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -847,6 +952,7 @@ class TestHubspotSourceRouting:logger=MagicMock(),resumable_source_manager=MagicMock(),use_search_path=True,+ api_version=HUBSPOT_API_VERSION_V3,)finally:HUBSPOT_ENDPOINTS["deals"].cursor_filter_property_field = original@@ -860,6 +966,7 @@ class TestHubspotSourceRouting:resumable_source_manager=MagicMock(),use_search_path=True,db_incremental_field_last_value=None,+ api_version=HUBSPOT_API_VERSION_V3,)# SourceResponse should be returned with partition settings preserved.assert resp.name == "deals"@@ -874,6 +981,7 @@ class TestHubspotSourceRouting:logger=MagicMock(),resumable_source_manager=MagicMock(),use_search_path=False,+ api_version=HUBSPOT_API_VERSION_V3,)assert resp.name == "deals"@@ -912,6 +1020,7 @@ class TestGetRowsFullRefresh:logger=logger,resumable_source_manager=manager,include_custom_props=False,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -944,6 +1053,7 @@ class TestGetRowsFullRefresh:logger=logger,resumable_source_manager=manager,include_custom_props=False,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -981,6 +1091,7 @@ class TestGetRowsFullRefresh:logger=logger,resumable_source_manager=manager,include_custom_props=False,+ api_version=HUBSPOT_API_VERSION_V3,))diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.pyindex c15ccfa835bc..bfbb2fce1e09 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py@@ -6,9 +6,15 @@ from unittest.mock import MagicMock, patchfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceInputsfrom products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import (DEFAULT_PROPS,+ HUBSPOT_API_VERSION_2026_03,+ HUBSPOT_API_VERSION_V3,HUBSPOT_ENDPOINTS,+ apply_crm_api_version,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.source import (+ HubspotSource,+ HubspotSourceOldConfig,)-from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.source import HubspotSourcefrom products.warehouse_sources.backend.types import IncrementalFieldType@@ -20,6 +26,7 @@ def _make_inputs(schema_id: str = "schema-1",team_id: int = 1,source_id: str = "source-1",+ api_version: str | None = None,) -> SourceInputs:return SourceInputs(schema_name=schema_name,@@ -34,6 +41,7 @@ def _make_inputs(job_id="job-1",logger=MagicMock(),reset_pipeline=reset_pipeline,+ api_version=api_version,)@@ -248,6 +256,72 @@ def test_missing_token_error_is_non_retryable(error_msg: str) -> None:)+class TestApiVersion:+ def test_defaults_to_v3_until_date_version_is_verified(self) -> None:+ src = HubspotSource()+ assert src.default_version == HUBSPOT_API_VERSION_V3+ # A source with no pin (a newly created one) resolves to the v3 default...+ assert src.resolve_api_version(None) == HUBSPOT_API_VERSION_V3+ # ...while a 2026-03 pin is honored verbatim so opt-in sources use the date version.+ assert src.resolve_api_version(HUBSPOT_API_VERSION_2026_03) == HUBSPOT_API_VERSION_2026_03++ def test_both_versions_supported(self) -> None:+ assert set(HubspotSource().supported_versions) == {HUBSPOT_API_VERSION_V3, HUBSPOT_API_VERSION_2026_03}++ @pytest.mark.parametrize(+ "path,api_version,expected",+ [+ # Legacy pin: paths are returned byte-for-byte, keeping the historical v3/v4 split.+ ("/crm/v3/objects/contacts", HUBSPOT_API_VERSION_V3, "/crm/v3/objects/contacts"),+ (+ "/crm/v4/associations/contacts/deals/batch/read",+ HUBSPOT_API_VERSION_V3,+ "/crm/v4/associations/contacts/deals/batch/read",+ ),+ # Date version: the version segment moves behind the resource name (objects,+ # properties, associations), matching HubSpot's documented date-based paths.+ ("/crm/v3/objects/contacts", HUBSPOT_API_VERSION_2026_03, "/crm/objects/2026-03/contacts"),+ ("/crm/v3/properties/deals", HUBSPOT_API_VERSION_2026_03, "/crm/properties/2026-03/deals"),+ (+ "/crm/v4/associations/contacts/deals/batch/read",+ HUBSPOT_API_VERSION_2026_03,+ "/crm/associations/2026-03/contacts/deals/batch/read",+ ),+ ],+ )+ def test_apply_crm_api_version(self, path: str, api_version: str, expected: str) -> None:+ assert apply_crm_api_version(path, api_version) == expected++ @pytest.mark.parametrize(+ "pin,expected",+ [+ (None, HUBSPOT_API_VERSION_V3),+ (HUBSPOT_API_VERSION_V3, HUBSPOT_API_VERSION_V3),+ (HUBSPOT_API_VERSION_2026_03, HUBSPOT_API_VERSION_2026_03),+ ],+ )+ def test_source_for_pipeline_threads_resolved_version(self, pin: str | None, expected: str) -> None:+ src = HubspotSource()+ old_config = HubspotSourceOldConfig.from_dict(+ {"hubspot_secret_key": "secret", "hubspot_refresh_token": "refresh"}+ )+ inputs = _make_inputs(should_use_incremental_field=False, api_version=pin)++ with (+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.source.hubspot_source",+ return_value=MagicMock(),+ ) as hubspot_source_mock,+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.source.hubspot_access_token_is_valid",+ return_value=True,+ ),+ ):+ src.source_for_pipeline(old_config, MagicMock(), inputs)++ assert hubspot_source_mock.call_args.kwargs["api_version"] == expected++@pytest.mark.parametrize("error_msg",[diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_hubspot_source.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_hubspot_source.pyindex d4f79d41b82c..ef009a4d3c8f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_hubspot_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_hubspot_source.py@@ -39,6 +39,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.hu_get_properties_str,get_rows,)+from products.warehouse_sources.backend.temporal.data_imports.sources.hubspot.settings import HUBSPOT_API_VERSION_V3from products.warehouse_sources.backend.temporal.data_imports.tests.e2e.conftest import run_external_data_job_workflowpytestmark = pytest.mark.usefixtures("minio_client")@@ -255,6 +256,7 @@ def test_get_rows_with_selected_properties_backfills_missing_columns():logger=logger,resumable_source_manager=mock_rsm,selected_properties=["email", "firstname"],+ api_version=HUBSPOT_API_VERSION_V3,))@@ -306,6 +308,7 @@ def test_get_rows_with_selected_properties_filters_invalid():logger=logger,resumable_source_manager=mock_rsm,selected_properties=["email", "nonexistent_prop"],+ api_version=HUBSPOT_API_VERSION_V3,))@@ -356,6 +359,7 @@ def test_get_rows_all_invalid_properties_falls_back_to_defaults():logger=logger,resumable_source_manager=mock_rsm,selected_properties=["totally_fake_1", "totally_fake_2"],+ api_version=HUBSPOT_API_VERSION_V3,))@@ -402,6 +406,7 @@ def test_get_rows_without_selected_properties_uses_defaults():logger=logger,resumable_source_manager=mock_rsm,selected_properties=None,+ api_version=HUBSPOT_API_VERSION_V3,))@@ -536,6 +541,7 @@ def test_get_rows_backfills_missing_properties():logger=logger,resumable_source_manager=mock_resumable_manager,include_custom_props=True,+ api_version=HUBSPOT_API_VERSION_V3,))