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): recognize "Invalid resource name" as non-retryable (#102410)

Tom Owers79ea4a38d3e9
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 23161c361f98..e20c5073be9c 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
@@ -628,6 +628,19 @@ def delete_all_temp_destination_tables(
# 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 BadRequest as e:
+ if "Invalid resource name" in str(e):
+ # A dataset/project ID containing characters BigQuery's resource-name validation
+ # rejects (e.g. a Dataset ID field mistakenly set to "project.dataset") makes
+ # `bq.dataset(...)` build an invalid path for this REST call, distinct from the
+ # "Invalid project ID"/"Invalid dataset ID" wording query jobs raise for the same
+ # misconfiguration (see `BigQuerySource.get_non_retryable_errors`). It's
+ # deterministic and already surfaces non-retryably elsewhere in the sync, so log
+ # quietly here too rather than capturing noise on every run for an affected source.
+ if logger:
+ logger.warning(f"Skipping temp table cleanup for dataset {dataset_id}: {e}")
+ else:
+ capture_exception(e)
except Exception as e:
capture_exception(e)
@@ -715,6 +728,7 @@ def validate_bigquery_credentials(
"Invalid project ID" in message
or "Invalid dataset ID" in message
or "ProjectId must be non-empty" in message
+ or "Invalid resource name" in message
):
return False, BIGQUERY_INVALID_IDENTIFIER_ERROR
if "was not found in location" in message or "Not found: Dataset" in message:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
index 1fb19602503e..ed38e791859c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
@@ -204,6 +204,12 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
BIGQUERY_INVALID_IDENTIFIER_ERROR: BIGQUERY_INVALID_IDENTIFIER_ERROR,
"Invalid dataset ID": BIGQUERY_INVALID_IDENTIFIER_ERROR,
"Invalid project ID": BIGQUERY_INVALID_IDENTIFIER_ERROR,
+ # `bq.dataset(...)`-based REST calls (`list_tables`, used by temp-table cleanup and
+ # credential validation) reject a malformed project/dataset ID with this resource-name
+ # wording instead of "Invalid project ID"/"Invalid dataset ID", which only query jobs
+ # raise for the same misconfiguration. Matched on the stable wording, not the volatile
+ # offending id.
+ "Invalid resource name": BIGQUERY_INVALID_IDENTIFIER_ERROR,
# Raised as a 400 BadRequest from job creation (POST .../jobs) when the location the
# client runs in — the custom region from the source form, or the dataset's own location
# auto-detected in `connect` — isn't a region BigQuery can run query jobs in, e.g.
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 1d2ba443ee48..742b3297dd8c 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
@@ -846,6 +846,26 @@ def test_bigquery_missing_selected_fields_is_non_retryable(observed_error):
assert all(non_retryable_errors[key] is not None for key in matching)
+ "observed_error",
+ [
+ # A malformed project/dataset ID (e.g. Dataset ID set to "project.dataset") makes
+ # `bq.dataset(...)`-based REST calls reject the request with this resource-name wording,
+ # distinct from the "Invalid project ID"/"Invalid dataset ID" wording query jobs raise for
+ # the same misconfiguration (see `test_bigquery_malformed_table_id_is_non_retryable`).
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/my-project.my_dataset/datasets/"
+ "my-project.my_dataset/tables?prettyPrint=false: Invalid resource name "
+ "projects/my-project.my_dataset; Project id: my-project.my_dataset",
+ ],
+)
+def test_bigquery_invalid_resource_name_is_non_retryable(observed_error):
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in observed_error]
+ assert matching, "Invalid resource name error should be recognised as non-retryable"
+ # Must map to the actionable identifier guidance, not just any non-null message.
+ assert all(non_retryable_errors[key] == BIGQUERY_INVALID_IDENTIFIER_ERROR for key in matching)
+
+
@pytest.mark.parametrize(
"transient_error",
[
@@ -901,11 +921,17 @@ 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"})),
+ BadRequest(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/my-project.my_dataset/datasets/"
+ "my-project.my_dataset/tables?prettyPrint=false: Invalid resource name "
+ "projects/my-project.my_dataset; Project id: my-project.my_dataset"
+ ),
],
)
def test_delete_all_temp_destination_tables_swallows_expected_errors_quietly(exception):
- """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."""
+ """Lost permissions, a deleted dataset, rejected credentials, or a malformed project/dataset ID
+ 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)
@@ -1230,6 +1256,15 @@ def test_bigquery_clients_refuse_non_google_token_uri_before_building_credential
(RefreshError("('invalid_grant: Invalid JWT Signature.', {})"), BIGQUERY_CREDENTIALS_REJECTED_ERROR, False),
(BadRequest('Invalid dataset ID "(default)"'), BIGQUERY_INVALID_IDENTIFIER_ERROR, False),
(BadRequest("400 ProjectId must be non-empty"), BIGQUERY_INVALID_IDENTIFIER_ERROR, False),
+ (
+ BadRequest(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/my-project.my_dataset/datasets/"
+ "my-project.my_dataset/tables?prettyPrint=false: Invalid resource name "
+ "projects/my-project.my_dataset; Project id: my-project.my_dataset"
+ ),
+ BIGQUERY_INVALID_IDENTIFIER_ERROR,
+ False,
+ ),
(
NotFound("404 Not found: Dataset my-project:my_dataset was not found in location US"),
BIGQUERY_DATASET_NOT_FOUND_ERROR,