Skip to content

: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.

feat(warehouse_sources): support dbt API version v3 (#74165)

Tom Owersc11047d8ad81
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/settings.py
index 0e09c29e7d9d..c1d199978dcd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/settings.py
@@ -2,8 +2,20 @@ from dataclasses import dataclass, field
from datetime import timedelta
from typing import Literal, Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSION
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
+# dbt Cloud's Administrative API runs two live versions: v3 (the vendor's recommended version) and
+# v2 (legacy). There is no v1 — UNVERSIONED_API_VERSION ("v1") is only the framework placeholder
+# pre-versioning rows carry. This source already reads every resource from whichever version serves
+# it: accounts/projects/environments/users on v3, jobs/runs on v2 (v3 exposes neither jobs/runs nor
+# a bare account-detail endpoint for the credential probe). That split is fixed by the vendor, so a
+# "v1"- and a "v3"-pinned source issue byte-for-byte identical requests and nothing branches on the
+# pin; declaring v3 only makes the source's public version metadata name the API it actually targets.
+DBT_API_VERSION_V3 = "v3"
+DBT_SUPPORTED_VERSIONS = (UNVERSIONED_API_VERSION, DBT_API_VERSION_V3)
+DBT_DEFAULT_VERSION = DBT_API_VERSION_V3
+
# Per-region base hostnames for the dbt Cloud Administrative API. Cell-based (e.g.
# https://ab123.us1.dbt.com) and single-tenant deployments use a custom base URL instead.
DBT_REGION_BASE_URLS: dict[str, str] = {
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/source.py
index 795da8932817..f051bf932f05 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/source.py
@@ -29,7 +29,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.dbt im
validate_credentials as validate_dbt_credentials,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.settings import (
+ DBT_DEFAULT_VERSION,
DBT_ENDPOINTS,
+ DBT_SUPPORTED_VERSIONS,
ENDPOINTS,
INCREMENTAL_FIELDS,
)
@@ -41,6 +43,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
class DbtSource(ResumableSource[DbtSourceConfig, DbtResumeConfig]):
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
api_docs_url = "https://docs.getdbt.com/docs/dbt-cloud-apis/overview" # coverage spans both Admin API v2 and v3
+ supported_versions = DBT_SUPPORTED_VERSIONS
+ default_version = DBT_DEFAULT_VERSION
@property
def source_type(self) -> ExternalDataSourceType:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt.py
index ad22040aae00..0d6ef07b56e7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt.py
@@ -270,6 +270,27 @@ class TestGetRows:
assert "order_by" not in _requested_query(session, 0)
assert session.get.call_args_list[0].kwargs["headers"]["Authorization"] == "Token token"
+ @pytest.mark.parametrize(
+ "endpoint, expected_path",
+ [
+ ("accounts", "/api/v3/accounts/"),
+ ("projects", "/api/v3/accounts/12345/projects/"),
+ ("environments", "/api/v3/accounts/12345/environments/"),
+ ("users", "/api/v3/accounts/12345/users/"),
+ # jobs and runs are v2-only — dbt v3 exposes neither, so the v3 default must keep
+ # reading them from v2; unifying them onto v3 would 404 every jobs/runs sync.
+ ("jobs", "/api/v2/accounts/12345/jobs/"),
+ ("runs", "/api/v2/accounts/12345/runs/"),
+ ],
+ )
+ def test_endpoint_uses_correct_dbt_api_version(self, endpoint, expected_path):
+ session = mock.MagicMock()
+ session.get.side_effect = [_page([])]
+
+ self._get_rows(session, _manager(), endpoint)
+
+ assert session.get.call_args_list[0].args[0].startswith(f"https://cloud.getdbt.com{expected_path}")
+
def test_state_saved_after_yield_only_when_more_pages_remain(self):
session = mock.MagicMock()
session.get.side_effect = [
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt_source.py
index 10ef6e6c9cad..cf4739e856e2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/dbt/tests/test_dbt_source.py
@@ -3,9 +3,10 @@ from unittest import mock
from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType, SourceFieldSelectConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSION
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.dbt import DbtResumeConfig
-from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.settings import ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.settings import DBT_API_VERSION_V3, ENDPOINTS
from products.warehouse_sources.backend.temporal.data_imports.sources.dbt.source import DbtSource
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.dbt import DbtSourceConfig
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -54,6 +55,13 @@ class TestDbtSource:
# lets an editor point the preserved credential at their own server or another account.
assert self.source.connection_host_fields == ["region", "custom_base_url", "account_id"]
+ def test_declares_v3_as_default_over_legacy_pin(self):
+ # New sources are stamped with default_version; a revert here silently pins them to the
+ # meaningless "v1" placeholder instead of dbt's recommended v3. The legacy label stays
+ # supported so existing "v1"-pinned rows keep resolving to their unchanged wire behaviour.
+ assert self.source.supported_versions == (UNVERSIONED_API_VERSION, DBT_API_VERSION_V3)
+ assert self.source.default_version == DBT_API_VERSION_V3
+
@pytest.mark.parametrize("expected_key", ["401 Client Error", "403 Client Error"])
def test_non_retryable_errors(self, expected_key):
assert any(expected_key in key for key in self.source.get_non_retryable_errors())