: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): treat invalid app client secret as internal config error (#71896)
Tom Owersa64053f7ab23
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 424781b0f69f..e64c170101b8 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@@ -83,6 +83,14 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O)return {"AADSTS650052": service_principal_friendly,+ # PostHog's own Azure AD application secret (BING_ADS_CLIENT_SECRET) is invalid or expired —+ # Microsoft rejects the token request with AADSTS7000215 for the app itself, not the connected+ # account. Reconnecting the integration can't fix it; only rotating PostHog's app secret can, so+ # this is internal config (None message), not customer-actionable. Wrapped by the SDK as+ # `OAuthTokenRequestException: invalid_client AADSTS7000215: …`, so it shares those two generic+ # substrings — it must precede both so handle_non_retryable doesn't surface the misleading+ # "reconnect your integration" message.+ "AADSTS7000215": None,# OAuth grant rejection by Microsoft (the bingads SDK raises OAuthTokenRequestException# whose str() format is "<error_code> <error_description>")."OAuthTokenRequestException": auth_friendly,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 0aead758e35c..3c156968f41d 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@@ -271,6 +271,12 @@ class TestBingAdsSource:"Failed to fetch customer ID: OAuthTokenRequestException: invalid_client AADSTS650052: ""The app is trying to access a service that your organization lacks a service principal for.",),+ # PostHog's own app secret is invalid/expired — internal config, not customer-actionable.+ (+ "AADSTS7000215",+ "Failed to fetch customer ID: OAuthTokenRequestException: error_code: invalid_client, "+ "error_description: AADSTS7000215: Invalid client secret provided.",+ ),# Bing rejects the request as invalid after auth succeeds (e.g. wrong/inaccessible Account ID).# The SDK raises suds.WebFault whose str() embeds a volatile TrackingId — match the stable phrase.(@@ -343,6 +349,25 @@ class TestBingAdsSource:assert "AADSTS650052" in friendly_errors[0]assert "service principal" in friendly_errors[0]+ def test_aadsts7000215_is_internal_config_not_customer_actionable(self):+ # AADSTS7000215 means PostHog's own app secret is invalid/expired. The message also contains+ # "OAuthTokenRequestException" and "invalid_client", both of which map to the customer-facing+ # "reconnect your integration" toast — so AADSTS7000215 must precede them and resolve to None,+ # keeping the misleading toast off an error only a PostHog config change can fix.+ non_retryable_errors = self.source.get_non_retryable_errors()+ keys = list(non_retryable_errors.keys())++ aadsts_index = keys.index("AADSTS7000215")+ assert aadsts_index < keys.index("OAuthTokenRequestException")+ assert aadsts_index < keys.index("invalid_client")++ error_message = (+ "Failed to fetch customer ID: OAuthTokenRequestException: error_code: invalid_client, "+ "error_description: AADSTS7000215: Invalid client secret provided."+ )+ friendly_errors = [msg for pattern, msg in non_retryable_errors.items() if pattern in error_message]+ assert friendly_errors[0] is None+def test_invalid_client_data_maps_to_account_guidance(self):# The dominant cause is a wrong/inaccessible Account ID (auth has already succeeded by this point),# so the toast must point at the Account ID rather than telling the user to reconnect OAuth.