: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-sheets): say a missing sheet may just be unshared (#102716)
Tom Owers6d129743e835
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/source.pyindex 72f7b57eebf3..09d717cfd2fa 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/source.py@@ -167,7 +167,13 @@ class GoogleSheetsSource(SimpleSource[GoogleSheetsSourceConfig]):"for example https://docs.google.com/spreadsheets/d/<id>/edit.",)except gspread.SpreadsheetNotFound:- return False, "Spreadsheet not found at URL provided"+ # The Sheets API answers an unshared sheet with a 404, the same as a deleted one, so+ # sharing is at least as likely as a wrong URL. Mirror the sync-time message.+ return (+ False,+ "PostHog couldn't find a sheet at that URL. Check the URL, and share the sheet with our service "+ f"account ({settings.GOOGLE_SHEETS_SERVICE_ACCOUNT_CLIENT_EMAIL}) as a Viewer.",+ )except PermissionError:return (False,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.pyindex 4020ae1e3224..4fced83a1e36 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py@@ -828,12 +828,20 @@ def test_validate_credentials_rejects_non_sheets_url_with_actionable_message():assert "Google Sheets URL" in (error_message or "")-def test_validate_credentials_permission_denied_names_service_account(settings):+ "open_error",+ [+ PermissionError(),+ # An unshared sheet 404s just like a deleted one, so this branch must offer sharing too.+ gspread.exceptions.SpreadsheetNotFound(mock.MagicMock()),+ ],+)+def test_validate_credentials_unshared_sheet_names_service_account(settings, open_error):settings.GOOGLE_SHEETS_SERVICE_ACCOUNT_CLIENT_EMAIL = "[email protected]"with mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.google_sheets.source.google_sheets_client") as mock_client:- mock_client.return_value.open_by_url.side_effect = PermissionError()+ mock_client.return_value.open_by_url.side_effect = open_errorconfig = GoogleSheetsSourceConfig(spreadsheet_url="https://docs.google.com/spreadsheets/d/fake")is_valid, error_message = GoogleSheetsSource().validate_credentials(config, team_id=1)