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 retrying an ambiguous-column query (#74715)

Tom Owersc8df1f75c826
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 307dbc2d55dd..67eb9ff9c93f 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
@@ -270,6 +270,17 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# The user must fix the source view/column; retrying just spams error tracking. Matched on
# BigQuery's stable wording, not the volatile job id/URL.
"Invalid NUMERIC value: NaN": "BigQuery couldn't complete a query for this source because it produced a NaN (not-a-number) value in a column typed NUMERIC, which that type can't represent. This is usually caused by a computed column or view doing arithmetic like division by zero. Please fix the underlying view or column in BigQuery, then re-enable the source.",
+ # Raised as a 400 BadRequest (reason `invalidQuery`) when the table or view being synced
+ # has a column name BigQuery can't resolve to a single source, e.g. "Column name x is
+ # ambiguous". We select each configured column by its own unqualified name (see
+ # `_get_query`/`_bq_select_clause` in `bigquery.py`), so this only happens when the
+ # underlying relation itself has the conflict — a view that joins tables sharing a column
+ # name, or a table/external table with two columns differing only by letter case. It's a
+ # deterministic property of the customer's view/table definition: the same query fails
+ # identically on every retry, so it just hammers BigQuery and spams error tracking. The
+ # user must fix the view or table definition. Matched on BigQuery's stable wording, not
+ # the volatile column name or [row:col] location.
+ "is ambiguous": "BigQuery couldn't run a query for this source because a column name in the table or view being synced is ambiguous. This usually happens when a view joins tables that share a column name, or two columns differ only by letter case. Retrying won't help — please update the view or table definition to remove the naming conflict (for example by aliasing the duplicate column), then reconnect the source.",
}
def validate_credentials(
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 d042d5eb3260..6b58fed83bc1 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
@@ -735,6 +735,26 @@ def test_bigquery_unparseable_private_key_is_non_retryable(observed_error):
assert all(non_retryable_errors[key] is not None for key in matching)
+ "observed_error",
+ [
+ # Column collision surfaced with the raw BigQuery [row:col] location.
+ "400 Column name organization is ambiguous at [1:113]; reason: invalidQuery, location: query, "
+ "message: Column name organization is ambiguous at [1:113]\n\nLocation: us-west1\nJob ID: cc9e1e07-9d3a-4fcc-a51c-09b2f4237894\n",
+ # Different column name and location — the match must not rely on either.
+ "400 Column name id is ambiguous at [2:45]; reason: invalidQuery, location: query, "
+ "message: Column name id is ambiguous at [2:45]",
+ ],
+)
+def test_bigquery_ambiguous_column_is_non_retryable(observed_error):
+ """A view/table whose own definition yields a colliding column name (e.g. a join of tables
+ sharing a column, or two columns differing only by case) makes every retry fail identically."""
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in observed_error]
+ assert matching, "Ambiguous column 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",
[