: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(google_ads): retry transient auth-backend hiccups instead of failing the sync (#82143)
Tom Owersb4b38982e8cf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.pyindex 10c19692581a..70c1c28568fe 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py@@ -643,6 +643,15 @@ _TRANSIENT_GRPC_STATUS_CODES = frozenset(# receive limit, not retrying, is what addresses it._RECEIVE_LIMIT_EXHAUSTED_SIGNATURE = "Received message larger than max"+# Google's own token-verification backend occasionally returns a bare ``UNKNOWN`` gRPC status+# carrying this message when it has a momentary internal hiccup — a genuinely rejected credential+# instead comes back as ``UNAUTHENTICATED`` / ``PERMISSION_DENIED`` (handled as non-retryable in+# ``GoogleAdsSource.get_non_retryable_errors``). Reports of this exact message on the Google Ads API+# support forum have been confirmed by Google as backend-side incidents, not request problems, and a+# retry after backoff typically succeeds. Matched on this specific message rather than the bare+# ``UNKNOWN`` status, which covers far too broad a range of unrelated failures to retry blindly.+_AUTH_BACKEND_UNKNOWN_ERROR_SIGNATURE = "Authentication backend unknown error"+def _is_transient_grpc_error(exc: BaseException) -> bool:"""Return True for a transient gRPC failure Google's guidance says to retry.@@ -656,6 +665,8 @@ def _is_transient_grpc_error(exc: BaseException) -> bool:"""if isinstance(exc, google_api_exceptions.ServiceUnavailable | google_api_exceptions.InternalServerError):return True+ if isinstance(exc, google_api_exceptions.Unknown):+ return _AUTH_BACKEND_UNKNOWN_ERROR_SIGNATURE in str(exc)candidate: typing.Any = exc.error if isinstance(exc, GoogleAdsException) else exc# ``ResourceExhausted`` exposes ``code`` as an HTTP int, not a callable ``StatusCode``, so the# gapic-wrapped form is matched by type rather than via the ``code()`` check below.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.pyindex f5c4804a00cb..42d03d561a35 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py@@ -905,6 +905,12 @@ class TestTransientGrpcErrorDetection:),False,),+ # A bare UNKNOWN status carrying Google's own auth-backend hiccup message is a confirmed+ # transient backend incident, not a rejected credential — ride it out in-process.+ (google_api_exceptions.Unknown("Authentication backend unknown error."), True),+ # Any other UNKNOWN-status error must not be retried blindly — the status alone is too+ # broad a signal, so only the specific known message is treated as transient.+ (google_api_exceptions.Unknown("Some other unrelated backend failure."), False),# A different gapic error must not be treated as transient.(google_api_exceptions.PermissionDenied("PERMISSION_DENIED"), False),# Google Ads API errors carry no transient gRPC status — they route through the existing