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 Azure DevOps API version 7.2 (#74157)

Tom Owers6f0321014401
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/azure_devops.py b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/azure_devops.py
index 60f3f6814eb3..184898991187 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/azure_devops.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/azure_devops.py
@@ -13,11 +13,31 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.settings import (
AZURE_DEVOPS_ENDPOINTS,
)
+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.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
AZURE_DEVOPS_BASE_URL = "https://dev.azure.com"
-API_VERSION = "7.1"
+
+# Source version labels. The legacy label predates versioning and keeps sending
+# api-version 7.1 so existing syncs are unchanged; 7.2 is the current GA stable API.
+AZURE_DEVOPS_VERSION_LEGACY = UNVERSIONED_API_VERSION
+AZURE_DEVOPS_VERSION_7_2 = "7.2"
+
+# Source label → `api-version` query param actually sent on the wire.
+_WIRE_API_VERSION: dict[str, str] = {
+ AZURE_DEVOPS_VERSION_LEGACY: "7.1",
+ AZURE_DEVOPS_VERSION_7_2: "7.2",
+}
+
+
+def wire_api_version(api_version: str) -> str:
+ try:
+ return _WIRE_API_VERSION[api_version]
+ except KeyError:
+ raise ValueError(f"Unsupported Azure DevOps API version: {api_version}")
+
+
PAGE_SIZE = 200
REQUEST_TIMEOUT_SECONDS = 60
# Rate limiting is 200 TSTUs per identity per sliding 5-minute window; 429s
@@ -75,15 +95,16 @@ def _flatten_revision(item: dict[str, Any]) -> dict[str, Any]:
return item
-def validate_credentials(organization: str, personal_access_token: str) -> bool:
+def validate_credentials(organization: str, personal_access_token: str, api_version: str) -> bool:
"""Confirm the PAT and organization are valid with a cheap projects probe.
Azure DevOps answers an invalid PAT with a 203 + HTML sign-in page rather
than a 401, so only an exact 200 counts."""
try:
org = _validate_organization(organization)
+ wire_version = wire_api_version(api_version)
response = _get_session(personal_access_token).get(
- f"{AZURE_DEVOPS_BASE_URL}/{quote(org)}/_apis/projects?{urlencode({'$top': 1, 'api-version': API_VERSION})}",
+ f"{AZURE_DEVOPS_BASE_URL}/{quote(org)}/_apis/projects?{urlencode({'$top': 1, 'api-version': wire_version})}",
timeout=10,
)
return response.status_code == 200
@@ -97,12 +118,14 @@ def get_rows(
endpoint: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[AzureDevOpsResumeConfig],
+ api_version: str,
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Any = None,
) -> Iterator[list[dict[str, Any]]]:
config = AZURE_DEVOPS_ENDPOINTS[endpoint]
session = _get_session(personal_access_token)
org = _validate_organization(organization)
+ wire_version = wire_api_version(api_version)
@retry(
retry=retry_if_exception_type((AzureDevOpsRetryableError, requests.ReadTimeout, requests.ConnectionError)),
@@ -111,7 +134,7 @@ def get_rows(
reraise=True,
)
def fetch(path: str, params: dict[str, Any]) -> requests.Response:
- url = f"{AZURE_DEVOPS_BASE_URL}/{quote(org)}{path}?{urlencode({**params, 'api-version': API_VERSION})}"
+ url = f"{AZURE_DEVOPS_BASE_URL}/{quote(org)}{path}?{urlencode({**params, 'api-version': wire_version})}"
response = session.get(url, timeout=REQUEST_TIMEOUT_SECONDS)
if response.status_code == 429 or response.status_code >= 500:
@@ -240,6 +263,7 @@ def azure_devops_source(
endpoint: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[AzureDevOpsResumeConfig],
+ api_version: str,
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
@@ -253,6 +277,7 @@ def azure_devops_source(
endpoint=endpoint,
logger=logger,
resumable_source_manager=resumable_source_manager,
+ api_version=api_version,
should_use_incremental_field=should_use_incremental_field,
db_incremental_field_last_value=db_incremental_field_last_value,
),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/source.py
index 0338960a8ee0..9c15e8a34dea 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/source.py
@@ -14,6 +14,8 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
SourceResponse,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops import (
+ AZURE_DEVOPS_VERSION_7_2,
+ AZURE_DEVOPS_VERSION_LEGACY,
AzureDevOpsResumeConfig,
azure_devops_source,
validate_credentials as validate_azure_devops_credentials,
@@ -40,7 +42,11 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class AzureDevOpsSource(ResumableSource[AzureDevOpsSourceConfig, AzureDevOpsResumeConfig]):
- api_docs_url = "https://learn.microsoft.com/en-us/rest/api/azure/devops"
+ api_docs_url = "https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning"
+
+ # The legacy label keeps sending api-version 7.1; 7.2 is the current GA stable API.
+ supported_versions = (AZURE_DEVOPS_VERSION_LEGACY, AZURE_DEVOPS_VERSION_7_2)
+ default_version = AZURE_DEVOPS_VERSION_7_2
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@@ -122,7 +128,10 @@ Your organization is the first path segment of your Azure DevOps URL — for `de
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
- if validate_azure_devops_credentials(config.organization, config.personal_access_token):
+ # Pre-creation calls pass no pin and resolve to default_version — the version new rows start on.
+ if validate_azure_devops_credentials(
+ config.organization, config.personal_access_token, self.resolve_api_version(api_version)
+ ):
return True, None
return False, "Invalid Azure DevOps credentials"
@@ -142,6 +151,7 @@ Your organization is the first path segment of your Azure DevOps URL — for `de
endpoint=inputs.schema_name,
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
+ api_version=self.resolve_api_version(inputs.api_version),
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops.py b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops.py
index 279fe52b9ec3..987d60d5adbc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops.py
@@ -6,6 +6,8 @@ import pytest
from unittest import mock
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops import (
+ AZURE_DEVOPS_VERSION_7_2,
+ AZURE_DEVOPS_VERSION_LEGACY,
AzureDevOpsAuthError,
AzureDevOpsResumeConfig,
_flatten_revision,
@@ -14,6 +16,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devo
azure_devops_source,
get_rows,
validate_credentials,
+ wire_api_version,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.settings import (
AZURE_DEVOPS_ENDPOINTS,
@@ -100,15 +103,29 @@ class TestValidateCredentials:
response.status_code = status_code
mock_session.return_value.get.return_value = response
- assert validate_credentials("myorg", "pat") is expected
+ assert validate_credentials("myorg", "pat", AZURE_DEVOPS_VERSION_7_2) is expected
@mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops.make_tracked_session"
)
def test_validate_credentials_rejects_bad_org_without_request(self, mock_session):
- assert validate_credentials("my org!", "pat") is False
+ assert validate_credentials("my org!", "pat", AZURE_DEVOPS_VERSION_7_2) is False
mock_session.return_value.get.assert_not_called()
+ @pytest.mark.parametrize("version, wire", [(AZURE_DEVOPS_VERSION_LEGACY, "7.1"), (AZURE_DEVOPS_VERSION_7_2, "7.2")])
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops.make_tracked_session"
+ )
+ def test_validate_credentials_sends_mapped_api_version(self, mock_session, version, wire):
+ response = mock.MagicMock()
+ response.status_code = 200
+ mock_session.return_value.get.return_value = response
+
+ validate_credentials("myorg", "pat", version)
+
+ url = mock_session.return_value.get.call_args.args[0]
+ assert parse_qs(urlparse(url).query)["api-version"] == [wire]
+
class TestGetRows:
@mock.patch(
@@ -121,7 +138,7 @@ class TestGetRows:
]
manager = _make_manager()
- batches = list(get_rows("myorg", "pat", "projects", mock.MagicMock(), manager))
+ batches = list(get_rows("myorg", "pat", "projects", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2))
assert [item["id"] for batch in batches for item in batch] == ["p1", "p2"]
second_url = mock_session.return_value.get.call_args_list[1].args[0]
@@ -137,7 +154,7 @@ class TestGetRows:
]
manager = _make_manager()
- batches = list(get_rows("myorg", "pat", "builds", mock.MagicMock(), manager))
+ batches = list(get_rows("myorg", "pat", "builds", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2))
assert batches == [[{"id": 1, "queueTime": "2024-01-01T00:00:00Z"}]]
build_url = mock_session.return_value.get.call_args_list[1].args[0]
@@ -162,6 +179,7 @@ class TestGetRows:
"builds",
mock.MagicMock(),
manager,
+ AZURE_DEVOPS_VERSION_7_2,
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2024, 1, 2, tzinfo=UTC),
)
@@ -182,7 +200,7 @@ class TestGetRows:
]
manager = _make_manager()
- batches = list(get_rows("myorg", "pat", "pull_requests", mock.MagicMock(), manager))
+ batches = list(get_rows("myorg", "pat", "pull_requests", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2))
assert len(batches) == 2
urls = [call.args[0] for call in mock_session.return_value.get.call_args_list[1:]]
@@ -206,7 +224,9 @@ class TestGetRows:
]
manager = _make_manager()
- batches = list(get_rows("myorg", "pat", "work_item_revisions", mock.MagicMock(), manager))
+ batches = list(
+ get_rows("myorg", "pat", "work_item_revisions", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2)
+ )
assert batches[0][0]["changed_date"] == "2024-01-01T00:00:00Z"
assert len(batches) == 2
@@ -220,7 +240,7 @@ class TestGetRows:
mock_session.return_value.get.return_value = _response({"values": [], "isLastBatch": True})
manager = _make_manager(AzureDevOpsResumeConfig(continuation_token="tok_resume"))
- list(get_rows("myorg", "pat", "work_item_revisions", mock.MagicMock(), manager))
+ list(get_rows("myorg", "pat", "work_item_revisions", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2))
url = mock_session.return_value.get.call_args.args[0]
assert parse_qs(urlparse(url).query)["continuationToken"] == ["tok_resume"]
@@ -241,6 +261,7 @@ class TestGetRows:
"work_item_revisions",
mock.MagicMock(),
manager,
+ AZURE_DEVOPS_VERSION_7_2,
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2024, 1, 2, tzinfo=UTC),
)
@@ -269,6 +290,7 @@ class TestGetRows:
"builds",
mock.MagicMock(),
manager,
+ AZURE_DEVOPS_VERSION_7_2,
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2024, 1, 2, tzinfo=UTC),
)
@@ -289,14 +311,16 @@ class TestGetRows:
manager = _make_manager()
with pytest.raises(AzureDevOpsAuthError):
- list(get_rows("myorg", "pat", "projects", mock.MagicMock(), manager))
+ list(get_rows("myorg", "pat", "projects", mock.MagicMock(), manager, AZURE_DEVOPS_VERSION_7_2))
class TestAzureDevOpsSourceResponse:
@pytest.mark.parametrize("endpoint", list(ENDPOINTS))
def test_response_metadata_per_endpoint(self, endpoint):
config = AZURE_DEVOPS_ENDPOINTS[endpoint]
- response = azure_devops_source("myorg", "pat", endpoint, mock.MagicMock(), _make_manager())
+ response = azure_devops_source(
+ "myorg", "pat", endpoint, mock.MagicMock(), _make_manager(), AZURE_DEVOPS_VERSION_7_2
+ )
assert response.name == endpoint
assert response.primary_keys == config.primary_keys
@@ -309,10 +333,35 @@ class TestAzureDevOpsSourceResponse:
assert response.partition_keys is None
def test_pull_requests_are_desc_sorted(self):
- response = azure_devops_source("myorg", "pat", "pull_requests", mock.MagicMock(), _make_manager())
+ response = azure_devops_source(
+ "myorg", "pat", "pull_requests", mock.MagicMock(), _make_manager(), AZURE_DEVOPS_VERSION_7_2
+ )
assert response.sort_mode == "desc"
@pytest.mark.parametrize("config", list(AZURE_DEVOPS_ENDPOINTS.values()))
def test_partition_keys_are_stable_fields(self, config):
if config.partition_key:
assert config.partition_key in {"queueTime", "creationDate", "changed_date"}
+
+
+class TestApiVersionDispatch:
+ @pytest.mark.parametrize("version, wire", [(AZURE_DEVOPS_VERSION_LEGACY, "7.1"), (AZURE_DEVOPS_VERSION_7_2, "7.2")])
+ def test_wire_api_version_maps_each_supported_label(self, version, wire):
+ assert wire_api_version(version) == wire
+
+ def test_wire_api_version_rejects_unknown_label(self):
+ # A silent fallthrough would send no api-version and track whatever the vendor defaults to.
+ with pytest.raises(ValueError):
+ wire_api_version("nope")
+
+ @pytest.mark.parametrize("version, wire", [(AZURE_DEVOPS_VERSION_LEGACY, "7.1"), (AZURE_DEVOPS_VERSION_7_2, "7.2")])
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops.make_tracked_session"
+ )
+ def test_get_rows_sends_pinned_api_version_on_the_wire(self, mock_session, version, wire):
+ mock_session.return_value.get.return_value = _response({"value": []})
+
+ list(get_rows("myorg", "pat", "projects", mock.MagicMock(), _make_manager(), version))
+
+ url = mock_session.return_value.get.call_args.args[0]
+ assert parse_qs(urlparse(url).query)["api-version"] == [wire]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops_source.py
index 5c39a08538c5..8f3ceaaec505 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/azure_devops/tests/test_azure_devops_source.py
@@ -4,6 +4,8 @@ from unittest import mock
from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops import (
+ AZURE_DEVOPS_VERSION_7_2,
+ AZURE_DEVOPS_VERSION_LEGACY,
AzureDevOpsResumeConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.settings import (
@@ -117,7 +119,8 @@ class TestAzureDevOpsSource:
assert is_valid is expected_valid
assert error_message == expected_message
- mock_validate.assert_called_once_with("myorg", "pat")
+ # No pin at creation time resolves to default_version.
+ mock_validate.assert_called_once_with("myorg", "pat", AZURE_DEVOPS_VERSION_7_2)
def test_get_resumable_source_manager_binds_resume_config(self):
inputs = mock.MagicMock()
@@ -134,6 +137,7 @@ class TestAzureDevOpsSource:
inputs.schema_name = "work_item_revisions"
inputs.should_use_incremental_field = True
inputs.db_incremental_field_last_value = "2024-01-02T03:04:05Z"
+ inputs.api_version = AZURE_DEVOPS_VERSION_7_2
manager = mock.MagicMock()
self.source.source_for_pipeline(self.config, manager, inputs)
@@ -144,9 +148,37 @@ class TestAzureDevOpsSource:
assert kwargs["personal_access_token"] == "pat"
assert kwargs["endpoint"] == "work_item_revisions"
assert kwargs["resumable_source_manager"] is manager
+ assert kwargs["api_version"] == AZURE_DEVOPS_VERSION_7_2
assert kwargs["should_use_incremental_field"] is True
assert kwargs["db_incremental_field_last_value"] == "2024-01-02T03:04:05Z"
+ @pytest.mark.parametrize(
+ "pinned, expected",
+ [
+ (None, AZURE_DEVOPS_VERSION_7_2),
+ ("", AZURE_DEVOPS_VERSION_7_2),
+ (AZURE_DEVOPS_VERSION_LEGACY, AZURE_DEVOPS_VERSION_LEGACY),
+ (AZURE_DEVOPS_VERSION_7_2, AZURE_DEVOPS_VERSION_7_2),
+ ],
+ )
+ @mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.source.azure_devops_source"
+ )
+ def test_source_for_pipeline_resolves_the_pin(self, mock_ado_source, pinned, expected):
+ inputs = mock.MagicMock()
+ inputs.schema_name = "projects"
+ inputs.should_use_incremental_field = False
+ inputs.api_version = pinned
+
+ self.source.source_for_pipeline(self.config, mock.MagicMock(), inputs)
+
+ assert mock_ado_source.call_args.kwargs["api_version"] == expected
+
+ def test_default_version_is_the_new_ga_version(self):
+ # New sources start on 7.2; the legacy label stays supported so existing pins keep working.
+ assert self.source.default_version == AZURE_DEVOPS_VERSION_7_2
+ assert set(self.source.supported_versions) == {AZURE_DEVOPS_VERSION_LEGACY, AZURE_DEVOPS_VERSION_7_2}
+
@mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.source.azure_devops_source"
)