: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_search_console): treat OAuth invalid_grant as non-retryable (#63345)
Tom Owers7025a6373312
diff --git a/posthog/temporal/data_imports/sources/google_search_console/source.py b/posthog/temporal/data_imports/sources/google_search_console/source.pyindex 26e04f49de66..d19e1eba20a9 100644--- a/posthog/temporal/data_imports/sources/google_search_console/source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/source.py@@ -46,6 +46,11 @@ class GoogleSearchConsoleSource("401 Client Error": "Your Google Search Console connection is invalid or expired. Please reconnect your account.","403 Client Error": "PostHog is not authorized to read this Search Console property. Please make sure the connected Google account has access to the property.","ACCESS_TOKEN_SCOPE_INSUFFICIENT": "Insufficient permissions. Please reconnect your Google Search Console account with the required scopes.",+ # `RefreshError: invalid_grant` is raised while AuthorizedSession refreshes the OAuth+ # access token — the stored refresh token has been revoked, expired, or invalidated+ # (app access revoked, password change, long inactivity). It never recovers on retry,+ # so stop the sync and ask the user to reconnect rather than burning activity retries.+ "invalid_grant": "Your Google Search Console connection has expired or been revoked. Please reconnect your account.",}def get_schemas(diff --git a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.pyindex 2556457eaa30..b0d277c063dd 100644--- a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py@@ -78,6 +78,19 @@ def test_get_resumable_source_manager_uses_resume_config():assert manager._data_class is GoogleSearchConsoleResumeConfig+ "error_message",+ [+ "invalid_grant",+ # The real RefreshError raised when AuthorizedSession refreshes a revoked/expired token.+ "RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})",+ ],+)+def test_invalid_grant_is_non_retryable(error_message):+ non_retryable_errors = GoogleSearchConsoleSource().get_non_retryable_errors()+ assert any(key in error_message for key in non_retryable_errors)++@pytest.mark.parametrize("status_code,expected_substring",[