: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): explain invalid client data on the account picker (#113702)
posthog[bot]7232106796d3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.pyindex f01df8e77ac1..36b330c4163e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py@@ -48,6 +48,15 @@ BING_ADS_INCREMENTAL_LOOKBACK_SECONDS: dict[str, int] = {BingAdsResource.DESTINATION_URL_PERFORMANCE_REPORT.value: 15 * 24 * 60 * 60,}+# The account picker runs before the user enters an Account ID, so the sync-time guidance does not apply there.+BING_ADS_LISTING_MESSAGE_OVERRIDES: dict[str, str] = {+ "Invalid client data": (+ "Microsoft returned 'Invalid client data' for the signed-in Microsoft login. This usually means that "+ "the login cannot access a Microsoft Advertising account. Reconnect your Bing Ads integration and sign in "+ "with a login that can access your Microsoft Advertising account."+ ),+}+@SourceRegistry.registerclass BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], OAuthMixin):@@ -257,7 +266,7 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], Ocatalog — entries with a None friendly message are internal config issues, not user-actionable."""for substring, friendly in self.get_non_retryable_errors().items():if friendly is not None and substring in error:- return friendly+ return BING_ADS_LISTING_MESSAGE_OVERRIDES.get(substring, friendly)return Nonedef get_oauth_accounts(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.pyindex 5c49ebde0a3e..0663de628e10 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py@@ -4,6 +4,9 @@ from unittest import mockfrom products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.source import BingAdsSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.utils import BingAdsResumeConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matches+from products.warehouse_sources.backend.temporal.data_imports.sources.common.integration_accounts import (+ IntegrationAccountListingError,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.bingads import (BingAdsSourceConfig,@@ -230,6 +233,40 @@ class TestBingAdsSource:assert error_message_matches(error_message, self.source.get_retryable_errors())assert not error_message_matches(error_message, self.source.get_non_retryable_errors())+ @pytest.mark.parametrize(+ "error_message,expected_fragment,unexpected_fragment",+ [+ (+ "Failed to fetch customer ID: Exception: Server raised fault: 'Invalid client data. "+ "Check the SOAP fault details for more information. TrackingId: abc-123.'",+ "cannot access a Microsoft Advertising account",+ "Account ID",+ ),+ (+ "Failed to fetch customer ID: Exception: Server raised fault: 'Invalid client data.' "+ "(AuthenticationTokenExpired: token expired)",+ "could not authenticate",+ "Invalid client data",+ ),+ ],+ )+ @mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.source.integration_secrets.get_secret",+ return_value="dev-token",+ )+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.source.BingAdsClient")+ @mock.patch.object(BingAdsSource, "get_oauth_integration")+ def test_get_oauth_accounts_listing_errors(+ self, mock_get_oauth, mock_client_cls, _mock_secret, error_message, expected_fragment, unexpected_fragment+ ):+ mock_client_cls.return_value.list_accounts.side_effect = ValueError(error_message)++ with pytest.raises(IntegrationAccountListingError) as exc_info:+ self.source.get_oauth_accounts(integration_id=1, team_id=self.team_id)++ assert expected_fragment in str(exc_info.value)+ assert unexpected_fragment not in str(exc_info.value)+def test_get_resumable_source_manager(self):"""Test that get_resumable_source_manager returns a manager that round-trips BingAdsResumeConfig."""inputs = mock.MagicMock()