: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(bing_ads): surface SOAP fault detail from campaigns fetch (#66483)
Tom Owersbbb88a0b3e39
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/client.pyindex 2cb6eaa1a766..56487c08cd08 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/client.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/client.py@@ -130,14 +130,17 @@ class BingAdsClient:self.authorization_data.account_id = account_idself.authorization_data.customer_id = customer_id- service_client = ServiceClient(- service="CampaignManagementService",- version=13,- authorization_data=self.authorization_data,- environment=ENVIRONMENT,- )+ try:+ service_client = ServiceClient(+ service="CampaignManagementService",+ version=13,+ authorization_data=self.authorization_data,+ environment=ENVIRONMENT,+ )- campaigns = service_client.GetCampaignsByAccountId(AccountId=account_id)+ campaigns = service_client.GetCampaignsByAccountId(AccountId=account_id)+ except Exception as e:+ raise _wrap_with_fault_detail(e, "Failed to fetch campaigns") from eresult = []if campaigns and campaigns.Campaign:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_client.pyindex a917455e8e94..447fa309c81e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_client.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_client.py@@ -217,3 +217,47 @@ class TestBingAdsClient:assert campaign_data["Name"] == "Test Campaign"assert campaign_data["Status"] == "Active"assert campaign_data["Languages"] == ["English"]++ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.client.ServiceClient")+ def test_get_campaigns_surfaces_soap_fault_detail(self, mock_service_client):+ """GetCampaignsByAccountId raises the same generic 'Invalid client data' WebFault as GetUser when+ the configured account is unusable. get_campaigns must funnel it through _wrap_with_fault_detail+ so the real error code in the SOAP detail reaches the retry framework instead of a raw WebFault.+ """+ webfault = _make_webfault(+ "Invalid client data. Check the SOAP fault details for more information. TrackingId: abc-123.",+ _ad_api_fault_detail("AuthenticationTokenExpired", "The authentication token has expired."),+ )+ mock_client_instance = mock_service_client.return_value+ mock_client_instance.GetCampaignsByAccountId.side_effect = webfault++ client = BingAdsClient(self.access_token, self.refresh_token, self.developer_token)+ with pytest.raises(ValueError) as exc_info:+ list(client.get_campaigns(self.account_id, self.customer_id))++ message = str(exc_info.value)+ assert "Failed to fetch campaigns" in message+ assert "AuthenticationTokenExpired" in message+ assert "Invalid client data" in message+ non_retryable_patterns = BingAdsSource().get_non_retryable_errors()+ assert any(pattern in message for pattern in non_retryable_patterns)++ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.client.ServiceClient")+ def test_get_campaigns_transient_failure_stays_retryable(self, mock_service_client):+ """A network/timeout failure from GetCampaignsByAccountId must keep its original signature and+ not coincidentally match a non-retryable auth pattern.+ """+ mock_client_instance = mock_service_client.return_value+ mock_client_instance.GetCampaignsByAccountId.side_effect = ConnectionError(+ "HTTPSConnectionPool(host='bingads.microsoft.com', port=443): Max retries exceeded"+ )++ client = BingAdsClient(self.access_token, self.refresh_token, self.developer_token)+ with pytest.raises(ValueError) as exc_info:+ list(client.get_campaigns(self.account_id, self.customer_id))++ message = str(exc_info.value)+ assert "Failed to fetch campaigns" in message+ assert "ConnectionError" in message+ non_retryable_patterns = BingAdsSource().get_non_retryable_errors()+ assert not any(pattern in message for pattern in non_retryable_patterns)