Skip to content

: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.

fix(google-ads): actionable error on permission-denied validation (#70983)

Tom Owerse749d1a8ef80
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
index 57a6570b3927..c4287c5e1b6d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
@@ -345,6 +345,18 @@ class GoogleAdsSource(
"Your Google Ads connection is no longer available — it may have been disconnected. "
"Please reconnect your Google Ads account.",
)
+ # A gRPC PERMISSION_DENIED ("The caller does not have permission") means the connected Google
+ # login can't access this customer ID — the wrong customer/manager (MCC) account, or access
+ # that was never granted. list_accessible_customers raises it as a raw _InactiveRpcError whose
+ # str() is a protobuf dump (with a per-request peer IP) the user can't act on, so surface an
+ # actionable prompt instead of leaking it, mirroring the MCC USER_PERMISSION_DENIED message.
+ if "PERMISSION_DENIED" in error_message or "caller does not have permission" in error_message:
+ return (
+ False,
+ "PostHog doesn't have permission to access this Google Ads account. Verify the "
+ "customer ID (and manager account, if using an MCC) is accessible to the connected "
+ "Google login, then reconnect your Google Ads account.",
+ )
# A transient Google-side blip (INTERNAL / UNAVAILABLE) stringifies as a raw gRPC status and
# protobuf failure dump the user can't act on. The sync rides these out in-process; here on
# the interactive create path we surface a clean retry prompt instead of leaking the dump.
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.py
index 4ef393b65370..56f0ca3db3ac 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
@@ -377,6 +377,27 @@ class TestValidateCredentials:
assert ok is False
assert "reconnect your Google Ads account" in (message or "")
+ def test_permission_denied_returns_actionable_message(self):
+ # A connected login that can't access the customer ID surfaces as a raw gRPC PERMISSION_DENIED
+ # dump (with a per-request peer IP) at validate time. Surface a clean, actionable prompt rather
+ # than leaking the protobuf dump to the wizard.
+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)
+ client = mock.Mock()
+ client.get_service.return_value.list_accessible_customers.side_effect = Exception(
+ 'status = StatusCode.PERMISSION_DENIED\n\tdetails = "The caller does not have permission"\n\t'
+ 'debug_error_string = "peer_address:ipv4:216.239.36.223:443"'
+ )
+ with mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.google_ads.google_ads_client",
+ return_value=client,
+ ):
+ ok, message = GoogleAdsSource().validate_credentials(config, team_id=1)
+
+ assert ok is False
+ assert "reconnect your Google Ads account" in (message or "")
+ assert "216.239.36.223" not in (message or "")
+ assert "StatusCode" not in (message or "")
+
def test_transient_google_side_error_returns_retry_message(self):
# A transient INTERNAL/UNAVAILABLE blip from Google stringifies as a raw gRPC status plus a
# protobuf failure dump. Surface a clean retry prompt instead of leaking that to the wizard.