: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 Harvey API version v2 (#74160)
Tom Owers7629d46d4df4
diff --git a/products/warehouse_sources/backend/migrations/0105_repin_harvey_api_version_v2.py b/products/warehouse_sources/backend/migrations/0105_repin_harvey_api_version_v2.pynew file mode 100644index 000000000000..f3fa6726dfbf--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0105_repin_harvey_api_version_v2.py@@ -0,0 +1,35 @@+from django.db import migrations++# Harvey retired its v1 Usage and Query History APIs on 2025-06-30 in favor of the v2 event-based+# schema. The source now defaults new instances to v2; this repins existing source-level pins from+# v1 to v2 so their stored version matches the wire the source already talks to and the in-product+# deprecation warning clears.+HARVEY_SOURCE_TYPE = "Harvey"+OLD_VERSION = "v1"+NEW_VERSION = "v2"+++def repin_harvey_v1_to_v2(apps, schema_editor):+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")++ # Only the source-level pin is touched. Schema-level `ExternalDataSchema.api_version` overrides+ # are user-managed (a customer intentionally pinned that schema) and are left alone — the+ # schema-level deprecation warning prompts the user to migrate those.+ #+ # NULL pins already resolve to the source's `default_version` (now v2), so they need no update.+ # Matching only `api_version="v1"` keeps this idempotent: a second run matches nothing.+ ExternalDataSource.objects.filter(source_type=HARVEY_SOURCE_TYPE, api_version=OLD_VERSION).update(+ api_version=NEW_VERSION+ )+++class Migration(migrations.Migration):+ dependencies = [+ ("warehouse_sources", "0104_easybill_source"),+ ]++ operations = [+ # Reverse is a no-op: nulling or downgrading pins would move customers back onto the+ # retired v1 label and clobber any deliberate post-migration pins.+ migrations.RunPython(repin_harvey_v1_to_v2, migrations.RunPython.noop, elidable=False),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 0194d59de641..ae11522abf23 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0104_easybill_source+0105_repin_harvey_api_version_v2diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/settings.pyindex 993a15b28f2d..3dff8dc08118 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/settings.py@@ -1,7 +1,18 @@from dataclasses import dataclass, field+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType+# Harvey moved its Usage and Query History APIs from v1 to the v2 event-based schema and retired v1+# on 2025-06-30. The source's history requests (sync and probe) already target the v2 endpoints+# (`/api/v2/history/...`) and read the v2 `events` payload, so both labels resolve to the same wire;+# the version bump is a declaration plus deprecation, with no request-layer branching. v1 keeps the+# pre-versioning UNVERSIONED default so already-pinned rows resolve unchanged.+HARVEY_API_VERSION_V1 = UNVERSIONED_API_VERSION+HARVEY_API_VERSION_V2 = "v2"+SUPPORTED_VERSIONS = (HARVEY_API_VERSION_V1, HARVEY_API_VERSION_V2)+DEFAULT_VERSION = HARVEY_API_VERSION_V2+HARVEY_BASE_URLS: dict[str, str] = {"us": "https://api.harvey.ai","eu": "https://eu.api.harvey.ai",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/source.pyindex 5b902e530059..b3bffd842ac3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/source.py@@ -1,3 +1,4 @@+import datetimefrom typing import Optional, castfrom posthog.schema import (@@ -15,7 +16,11 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelineSourceInputs,SourceResponse,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ FieldType,+ ResumableSource,+ VersionDeprecation,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (CanonicalDescriptions,)@@ -30,15 +35,24 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.harvey.harvalidate_credentials as validate_harvey_credentials,)from products.warehouse_sources.backend.temporal.data_imports.sources.harvey.settings import (+ DEFAULT_VERSION,ENDPOINTS,+ HARVEY_API_VERSION_V1,HARVEY_ENDPOINTS,INCREMENTAL_FIELDS,+ SUPPORTED_VERSIONS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass HarveySource(ResumableSource[HarveySourceConfig, HarveyResumeConfig]):+ supported_versions = SUPPORTED_VERSIONS+ default_version = DEFAULT_VERSION+ # v1's Usage and Query History APIs were retired on 2025-06-30. The source already reads the v2+ # endpoints for both labels, so v1 stays supported (pinned rows keep working) while carrying the+ # sunset date that lights up the generic in-product deprecation warning.+ deprecated_versions = (VersionDeprecation(version=HARVEY_API_VERSION_V1, sunset_at=datetime.date(2025, 6, 30)),)api_docs_url = "https://developers.harvey.ai/"lists_tables_without_credentials = True # static endpoint catalog — safe for public docsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/tests/test_harvey_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/tests/test_harvey_source.pyindex da43add2df37..81e5aa2ec3c0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/tests/test_harvey_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/harvey/tests/test_harvey_source.py@@ -1,3 +1,4 @@+import datetimefrom typing import Anyfrom unittest import mock@@ -46,6 +47,18 @@ class TestHarveySource:def test_source_type(self) -> None:assert self.source.source_type == ExternalDataSourceType.HARVEY+ def test_v1_is_deprecated_with_vendor_sunset_and_default_is_v2(self) -> None:+ # New sources start on v2; v1 stays supported so already-pinned rows keep resolving to the+ # unchanged v2 wire, but it carries Harvey's 2025-06-30 sunset date so the generic+ # in-product deprecation warning fires.+ assert self.source.default_version == "v2"+ assert set(self.source.supported_versions) == {"v1", "v2"}++ deprecation = self.source.get_version_deprecation("v1")+ assert deprecation is not None+ assert deprecation.sunset_at == datetime.date(2025, 6, 30)+ assert self.source.get_version_deprecation("v2") is None+def test_connection_host_fields_includes_region(self) -> None:# `region` selects the host the stored API token is sent to, so editing it must re-require the secret.assert self.source.connection_host_fields == ["region"]