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 a NaN-in-NUMERIC value from a source view (#74684)

Tom Owers9f6e438b4994
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 0963356805fc..307dbc2d55dd 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
@@ -260,6 +260,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# source view. Matched on BigQuery's stable wording, not the volatile peak-usage percentage
# or job id.
BIGQUERY_RESOURCES_EXCEEDED_ERROR: "BigQuery couldn't run a query for this source because it exceeded the memory allowed for a single query. This is usually caused by heavy sorts or analytic (window) functions over a large table or view. Retrying won't help — please reduce how much data you're syncing (for example add row filters or an incremental field), or simplify the source view, then re-enable the source.",
+ # Raised as a 400 BadRequest from `jobs.getQueryResults` (the poll `_run_destination_query_
+ # with_job_retry` / `_query_result_with_job_retry` in `bigquery.py` do while awaiting a query
+ # job) when the job's result set holds a NaN in a column typed NUMERIC/BIGNUMERIC — that type
+ # can't represent NaN the way FLOAT64 can. This traces back to the source table or view itself
+ # (a computed column doing arithmetic like division by zero) rather than anything our SELECT
+ # constructs, so it's a deterministic property of the customer's data: the same query keeps
+ # producing the same NaN on every retry, and Google's own default job-retry doesn't cover it.
+ # 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.",
}
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 6647114e1f2e..d042d5eb3260 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
@@ -1281,6 +1281,26 @@ def test_non_retryable_errors_match_unparseable_view(observed_error):
assert any(key in observed_error for key in non_retryable_errors)
+ "observed_error",
+ [
+ # A NaN in a NUMERIC-typed column, surfaced from `jobs.getQueryResults` while polling a query
+ # job — BigQuery's NUMERIC type can't represent NaN the way FLOAT64 can.
+ str(
+ BadRequest(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/p/queries/j?maxResults=0"
+ "&location=EU&prettyPrint=false: Invalid NUMERIC value: NaN\n\nLocation: EU\nJob ID: j"
+ )
+ ),
+ ],
+)
+def test_non_retryable_errors_match_numeric_nan(observed_error):
+ """A NUMERIC-typed column holding NaN traces back to the customer's source view/data, and the
+ same query keeps producing it on every retry — the user must fix the underlying view/column."""
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ assert any(key in observed_error for key in non_retryable_errors)
+
+
@pytest.mark.parametrize(
"observed_error",
[