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): treat malformed dataset id table error as non-retryable (#63720)

Tom Owerse8a43bb010ab
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.py
index 778f6a651a3c..5a94955b050a 100644
--- a/posthog/temporal/data_imports/sources/bigquery/source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/source.py
@@ -75,6 +75,12 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# so match the stable phrasing here. Retrying can't recover — the user must fix the
# dataset or set the correct region.
"was not found in location": "BigQuery couldn't find the configured dataset or table. It may have been deleted or renamed, or it may live in a different region — verify your dataset and table names, and set the dataset region in your source configuration if it isn't in the US.",
+ # Raised by google-cloud-bigquery's `TableReference.from_string` when a table id has
+ # more than the three `project.dataset.table` components. This happens when the
+ # Dataset ID field is set to `project.dataset` instead of just `dataset` — we then
+ # build `project.project.dataset.table` and the client rejects it. It's a deterministic
+ # config error, so retrying never succeeds.
+ "table_id must be a fully-qualified ID in standard SQL format": "Your BigQuery Dataset ID looks misconfigured — it should be just the dataset name (for example `analytics`), not `project.dataset`. Please update the Dataset ID in your source configuration.",
# Raised from the shared `evolve_pyarrow_schema` in `pipelines/pipeline/utils.py`
# when an integer column's source type was widened (e.g. `INT64` widened from a
# narrower numeric type) after the destination table was created with the narrower
diff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
index 72acb910bbc9..45432f394c20 100644
--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -294,17 +294,40 @@ def test_non_retryable_errors_match_rejected_credentials(observed_error):
assert any(key in observed_error for key in non_retryable_errors)
+ "observed_error",
+ [
+ # Raised when the Dataset ID is `project.dataset`, so we build a 4-component table id.
+ 'table_id must be a fully-qualified ID in standard SQL format, e.g., "project.dataset.table_id", '
+ "got immortal-407108.immortal-407108.analytics_529249625.events_20260325",
+ 'table_id must be a fully-qualified ID in standard SQL format, e.g., "project.dataset.table_id", '
+ "got immortal-407108.immortal-407108.analytics_529249625.__posthog_import_abc_def_123",
+ ],
+)
+def test_bigquery_malformed_table_id_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, "Malformed table id error should be recognised as non-retryable"
+ assert all(non_retryable_errors[key] is not None for key in matching)
+
+
@pytest.mark.parametrize(
"transient_error",
[
# A token refresh that failed for a transient reason must stay retryable.
"RefreshError: ('Failed to retrieve token', {'error': 'internal_failure'})",
"RefreshError: HTTPError 503 Service Unavailable",
+ "Connection reset by peer",
+ "ReadTimeout: The read operation timed out",
+ "503 Service Unavailable",
],
)
def test_non_retryable_errors_does_not_match_transient_refresh_failures(transient_error):
+ """Transient errors must not match any non-retryable key, so they stay retryable. Mirrors the
+ real matching mechanism (substring against every key) to guard against an overly broad key."""
non_retryable_errors = BigQuerySource().get_non_retryable_errors()
- assert not any(key in transient_error for key in non_retryable_errors)
+ matching = [key for key in non_retryable_errors if key in transient_error]
+ assert not matching, f"Transient error should remain retryable, but matched keys: {matching}"
def _run_delete_all_temp_destination_tables(side_effect, logger):