: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 client data" SOAP fault as non-retryable (#63965)
Tom Owers3d082cfecf3b
diff --git a/posthog/temporal/data_imports/sources/bing_ads/source.py b/posthog/temporal/data_imports/sources/bing_ads/source.pyindex 6bf8e3fa6d91..f4b0d3a7dc91 100644--- a/posthog/temporal/data_imports/sources/bing_ads/source.py+++ b/posthog/temporal/data_imports/sources/bing_ads/source.py@@ -70,6 +70,19 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O"AuthenticationFailed": auth_friendly,"InvalidCredentials": auth_friendly,"OAuthTokenExpired": auth_friendly,+ # Bing rejects the SOAP request as invalid *after* auth succeeds — the configured Account ID+ # is wrong or the connected Microsoft Advertising user can't access it. The SDK raises this as+ # `suds.WebFault("Server raised fault: 'Invalid client data. Check the SOAP fault details for+ # more information. TrackingId: <uuid>.'")`. The fault is deterministic (the same bad request+ # always reproduces it), so retrying can't recover — the customer has to fix the Account ID or+ # grant the connected account access. Match the stable phrase only; the TrackingId is volatile.+ # This does not catch transient Bing faults like "Server raised fault: 'Internal Error'".+ "Invalid client data": (+ "Bing Ads rejected the request as invalid. This usually means the configured Account ID is "+ "incorrect, or the connected Bing Ads account does not have access to it. Please check the "+ "Account ID in your source settings and that the connected account can access it, then "+ "reconfigure your Bing Ads source."+ ),# Integration row was deleted/disconnected while a scheduled job still references it.# Raised by OAuthMixin.get_oauth_integration as `ValueError("Integration not found: <id>")`;# the id is volatile, so match only the stable prefix. Retrying can't recreate the row —diff --git a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.pyindex 9351f986d50e..997e25e05f5d 100644--- a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py+++ b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py@@ -266,6 +266,13 @@ 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.",),+ # 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.+ (+ "Invalid client data",+ "Server raised fault: 'Invalid client data. Check the SOAP fault details for more "+ "information. TrackingId: 9471598f-2992-4c98-9d96-cbe84a0ddb47.'",+ ),# Integration deleted/disconnected — OAuthMixin.get_oauth_integration raises# `ValueError("Integration not found: <id>")`; match only the volatile-id-free prefix.("Integration not found", "Integration not found: 160672"),@@ -319,6 +326,27 @@ class TestBingAdsSource:assert "AADSTS650052" in friendly_errors[0]assert "service principal" in friendly_errors[0]+ 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.+ non_retryable_errors = self.source.get_non_retryable_errors()+ error_message = (+ "Server raised fault: 'Invalid client data. Check the SOAP fault details for more "+ "information. TrackingId: 9471598f-2992-4c98-9d96-cbe84a0ddb47.'"+ )+ friendly_errors = [msg for pattern, msg in non_retryable_errors.items() if pattern in error_message]++ assert friendly_errors[0] is not None+ assert "Account ID" in friendly_errors[0]++ def test_transient_bing_internal_error_fault_stays_retryable(self):+ # A generic Bing-side fault ("Internal Error") is transient and must keep retrying — it must not+ # be caught by the "Invalid client data" pattern.+ non_retryable_errors = self.source.get_non_retryable_errors()+ transient_message = "Server raised fault: 'Internal Error. TrackingId: abc-123.'"++ assert not any(pattern in transient_message for pattern in non_retryable_errors)+def test_get_resumable_source_manager(self):"""Test that get_resumable_source_manager returns a manager that round-trips BingAdsResumeConfig."""inputs = mock.MagicMock()