: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): handle login with no accessible ads accounts (#72652)
Tom Owers9bc203a60a2f
diff --git a/posthog/models/integration.py b/posthog/models/integration.pyindex 406e33c72f6f..d93a5c860fae 100644--- a/posthog/models/integration.py+++ b/posthog/models/integration.py@@ -1867,7 +1867,9 @@ class GoogleAdsIntegration:return accounts- for account in accessible_accounts["resourceNames"]:+ # A Google login with no accessible Ads accounts gets a 200 with an empty body, so+ # `resourceNames` is absent (proto3 omits empty repeated fields) rather than an empty list.+ for account in accessible_accounts.get("resourceNames", []):all_accounts = dfs(account.split("/")[1], all_accounts, account.split("/")[1])return all_accountsdiff --git a/posthog/models/test/test_integration_model.py b/posthog/models/test/test_integration_model.pyindex 980a53197ce8..9f111cc5928e 100644--- a/posthog/models/test/test_integration_model.py+++ b/posthog/models/test/test_integration_model.py@@ -3091,6 +3091,19 @@ class TestGoogleAdsIntegrationModel(BaseTest):assert client["level"] == "1"assert client["parent_id"] == "6501924158"+ @override_settings(GOOGLE_ADS_DEVELOPER_TOKEN="dev_token")+ @patch("posthog.models.integration.requests.request")+ def test_accessible_accounts_empty_when_login_has_no_accessible_customers(self, mock_request):+ # A Google login with no accessible Ads accounts gets a 200 with an empty body, so `resourceNames`+ # is absent rather than an empty list — this must yield no accounts, not raise KeyError.+ accessible = MagicMock(status_code=200)+ accessible.json.return_value = {}+ mock_request.return_value = accessible++ accounts = GoogleAdsIntegration(self._integration()).list_google_ads_accessible_accounts()++ assert accounts == []+class TestPinterestAdsIntegrationDisplayName(BaseTest):@parameterized.expand(