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(bigquery): stop capturing rejected-credential errors during temp table cleanup (#67377)

Tom Owersb548286c7f95
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
index f09ce773ee87..28bcbb8f1542 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
@@ -395,11 +395,15 @@ def delete_all_temp_destination_tables(
bq.delete_table(table.reference)
if logger:
logger.debug(f"Deleted bigquery table {table.table_id}")
- except (Forbidden, NotFound) as e:
+ except (Forbidden, NotFound, RefreshError) as e:
# Best-effort cleanup. If the service account has lost permission to list/delete
- # tables, or the dataset no longer exists, there's nothing to recover here — log
- # quietly rather than capturing an expected, non-actionable condition that would
- # otherwise fire on every sync for an affected source.
+ # tables, the dataset no longer exists, or a token refresh fails for any reason
+ # (rejected credentials from a rotated/revoked key — `RefreshError: invalid_grant` — or
+ # a transient refresh error), there's nothing to recover here. Rejected credentials, the
+ # common case, are already surfaced with an actionable message on the main sync path via
+ # `get_non_retryable_errors`; a transient refresh failure just leaves temp tables to be
+ # cleaned up on the next run. Log quietly rather than capturing an expected,
+ # non-actionable condition that would otherwise fire on every sync for an affected source.
if logger:
logger.warning(f"Skipping temp table cleanup for dataset {dataset_id}: {e}")
except Exception as e:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
index 5e2bba6ae0e0..1564440939bd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -586,11 +586,12 @@ def _run_delete_all_temp_destination_tables(side_effect, logger):
[
Forbidden("Access Denied: Permission bigquery.tables.list denied on dataset"),
NotFound("Dataset not found (or it may not exist)"),
+ RefreshError(("invalid_grant: Invalid JWT Signature.", {"error": "invalid_grant"})),
],
)
def test_delete_all_temp_destination_tables_swallows_expected_errors_quietly(exception):
- """Lost permissions or a deleted dataset during best-effort cleanup must NOT be
- captured to error tracking — it's expected and fires on every sync otherwise."""
+ """Lost permissions, a deleted dataset, or rejected credentials during best-effort cleanup
+ must NOT be captured to error tracking — it's expected and fires on every sync otherwise."""
logger = mock.MagicMock()
mock_capture = _run_delete_all_temp_destination_tables(exception, logger)