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_sheets): treat 404 entity-not-found reads as non-retryable (#69610)

Tom Owers490f093f0b3a
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.py
index 28efb6709b4f..d10c89048823 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
@@ -47,6 +47,12 @@ class GoogleSheetsSource(SimpleSource[GoogleSheetsSourceConfig]):
# `str(SpreadsheetNotFound)` is otherwise just `<Response [404]>`, with nothing to match.
# Retrying cannot recover.
"Spreadsheet not found": "Import failed: the Google Sheet could not be found. It may have been deleted or moved. Please check the spreadsheet URL and that it is shared with our service account.",
+ # The values-read calls (`get_all_values`/`get_all_records`) hit the Sheets API directly and
+ # gspread does NOT wrap their 404 into `SpreadsheetNotFound` — it raises the raw `APIError`,
+ # whose `str()` is "APIError: [404]: Requested entity was not found." (Google's stable 404
+ # text). So the sheet/worksheet vanishing mid-read bypasses the `SpreadsheetNotFound` branch
+ # above and would be retried forever. The 404 is deterministic — retrying cannot recover.
+ "Requested entity was not found": "Import failed: the Google Sheet or worksheet could not be found. It may have been deleted or moved, or is no longer shared with our service account. Please check the spreadsheet URL and its sharing settings.",
}
def get_schemas(
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.py
index 070d1a29d65c..eedfabee3a60 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
@@ -427,17 +427,23 @@ def test_google_sheets_source_reads_blank_cells_as_null():
mock_worksheet.get_all_records.assert_called_once_with(default_blank=None)
-def test_permission_error_is_non_retryable():
- """The message we re-raise from gspread's bare PermissionError must be a
- substring match for one of the source's non-retryable error keys, otherwise
- we'd retry a 403 forever."""
- source = GoogleSheetsSource()
- non_retryable_errors = source.get_non_retryable_errors()
-
- raised = PermissionError(_PERMISSION_DENIED_MESSAGE)
- error_msg = str(raised)
+ "error",
+ [
+ # gspread's bare 403 PermissionError, re-raised with a stable message.
+ pytest.param(PermissionError(_PERMISSION_DENIED_MESSAGE), id="permission_denied"),
+ # Values-read 404s stay a raw APIError (not SpreadsheetNotFound), so str() is
+ # "APIError: [404]: Requested entity was not found." — a deleted/moved/unshared sheet hit mid-read.
+ pytest.param(_api_error(404, "Requested entity was not found.", "NOT_FOUND"), id="entity_not_found_404"),
+ ],
+)
+def test_error_string_matches_a_non_retryable_key(error):
+ """The framework classifies non-retryable errors by substring-matching `str(exc)` against the
+ source's keys. Each error the source surfaces for a permanent failure must match a key, otherwise
+ a deterministic 403/404 gets retried forever."""
+ non_retryable_errors = GoogleSheetsSource().get_non_retryable_errors()
- assert any(key in error_msg for key in non_retryable_errors)
+ assert any(key in str(error) for key in non_retryable_errors)
@pytest.mark.parametrize(