: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
fix(azure-devops): name unexpected status in validation error (#81055)
Tom Owers8e70b925ff09
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.pyindex 107159eb9aea..6fa527b9a187 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@@ -106,7 +106,16 @@ _FORBIDDEN_MESSAGE = ()_ORGANIZATION_NOT_FOUND_MESSAGE = "Azure DevOps organization not found. Please check the organization name."_UNREACHABLE_MESSAGE = "Couldn't reach Azure DevOps to validate your credentials. Please try again in a few minutes."-_GENERIC_INVALID_MESSAGE = "Invalid Azure DevOps credentials"+++def _unexpected_status_message(status_code: int) -> str:+ # Any status the probe doesn't map explicitly (a 429, a 5xx, an unexpected redirect) lands here.+ # Name the status and point at both inputs rather than asserting the credentials are invalid,+ # which misdirects the user when the real cause is throttling or an Azure-side error.+ return (+ f"Azure DevOps returned an unexpected response (HTTP {status_code}). "+ "Check your organization name and personal access token, then try again."+ )def validate_credentials(organization: str, personal_access_token: str, api_version: str) -> tuple[bool, str | None]:@@ -139,7 +148,7 @@ def validate_credentials(organization: str, personal_access_token: str, api_versreturn False, _FORBIDDEN_MESSAGEif status_code == 404:return False, _ORGANIZATION_NOT_FOUND_MESSAGE- return False, _GENERIC_INVALID_MESSAGE+ return False, _unexpected_status_message(status_code)def get_rows(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.pyindex 8d63e0c05156..01f7939542c3 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@@ -113,6 +113,23 @@ class TestValidateCredentials:assert validate_credentials("myorg", "pat", AZURE_DEVOPS_VERSION_7_2) == expected+ @pytest.mark.parametrize("status_code", [429, 500, 503])+ @mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops.make_tracked_session"+ )+ def test_validate_credentials_unexpected_status_names_the_status(self, mock_session, status_code):+ # A throttled or Azure-side failure must not be reported as invalid credentials; the message+ # names the status and stays actionable.+ response = mock.MagicMock()+ response.status_code = status_code+ mock_session.return_value.get.return_value = response++ is_valid, error = validate_credentials("myorg", "pat", AZURE_DEVOPS_VERSION_7_2)++ assert is_valid is False+ assert str(status_code) in (error or "")+ assert "Invalid Azure DevOps credentials" not in (error or "")+@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.azure_devops.azure_devops.make_tracked_session")