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 missing-table errors from the row-count probe (#69966)

Tom Owersd4d361ff7895
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 d50802dcf42d..bf3218a6891c 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
@@ -638,6 +638,23 @@ def _has_duplicate_primary_keys(table: bigquery.Table, client: bigquery.Client,
return False
+def _is_missing_table_or_dataset(error: Exception) -> bool:
+ """True for a table/dataset that's absent from the region the query job runs in.
+
+ BigQuery raises a `NotFound` whose `str()` is "Not found: Table <id> was not found in
+ location EU" (or "Not found: Dataset ..." / "... was not found in location ...") when the
+ table was deleted or renamed after schema discovery selected it, or lives in a different
+ region than the one we query. That's a user-side condition the main read path already
+ surfaces non-retryably (see `BigQuerySource.get_non_retryable_errors`), so the best-effort
+ row-count probe shouldn't also capture it as error-tracking noise. Distinct from the
+ transient "Not found: Job" lookup race, which is retried before reaching here.
+ """
+ if not isinstance(error, NotFound):
+ return False
+ message = str(error)
+ return "was not found in location" in message or "Not found: Table" in message or "Not found: Dataset" in message
+
+
def _get_rows_to_sync(
table: bigquery.Table,
client: bigquery.Client,
@@ -683,7 +700,8 @@ def _get_rows_to_sync(
return 0
except Exception as e:
logger.debug(f"_get_rows_to_sync: Error: {e}. Using 0 as rows to sync", exc_info=e)
- capture_exception(e)
+ if not _is_missing_table_or_dataset(e):
+ capture_exception(e)
return 0
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 50f596c467c4..20314bfe945e 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
@@ -425,6 +425,63 @@ def test_bigquery_get_rows_to_sync_retries_transient_job_not_found(mock_sleep):
mock_capture.assert_not_called()
+def test_bigquery_get_rows_to_sync_skips_capture_when_table_missing():
+ # A table deleted/renamed after schema discovery (or absent from the queried region) makes the
+ # COUNT query raise a terminal NotFound. The main read path already surfaces this non-retryably,
+ # so the best-effort probe must fall back to 0 without capturing error-tracking noise.
+ table = mock.MagicMock(project="proj", dataset_id="ds", table_id="t")
+ table.schema = [SimpleNamespace(name="age", field_type="INTEGER")]
+ client = mock.MagicMock()
+ job = mock.MagicMock()
+ job.result.side_effect = NotFound("404 Not found: Table proj:ds.t was not found in location EU")
+ client.query.return_value = job
+
+ with mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.bigquery.capture_exception"
+ ) as mock_capture:
+ result = _get_rows_to_sync(
+ table=table,
+ client=client,
+ should_use_incremental_field=False,
+ db_incremental_field_last_value=None,
+ logger=mock.MagicMock(),
+ row_filters=[
+ ValidatedRowFilter(column="age", operator="IN", value=[21, 30], category=ColumnTypeCategory.INTEGER)
+ ],
+ )
+
+ assert result == 0
+ mock_capture.assert_not_called()
+
+
+def test_bigquery_get_rows_to_sync_captures_unexpected_error():
+ # A NotFound is only skipped for the missing-table/region wording; an unrelated failure must
+ # still be captured so genuine bugs stay visible.
+ table = mock.MagicMock(project="proj", dataset_id="ds", table_id="t")
+ table.schema = [SimpleNamespace(name="age", field_type="INTEGER")]
+ client = mock.MagicMock()
+ job = mock.MagicMock()
+ job.result.side_effect = ValueError("something unexpected")
+ client.query.return_value = job
+
+ with mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.bigquery.capture_exception"
+ ) as mock_capture:
+ result = _get_rows_to_sync(
+ table=table,
+ client=client,
+ should_use_incremental_field=False,
+ db_incremental_field_last_value=None,
+ logger=mock.MagicMock(),
+ row_filters=[
+ ValidatedRowFilter(column="age", operator="IN", value=[21, 30], category=ColumnTypeCategory.INTEGER)
+ ],
+ )
+
+ assert result == 0
+ mock_capture.assert_called_once()
+
+
def test_bigquery_get_query_in_filter_expands_to_one_param_per_value():
bq_table = mock.MagicMock(dataset_id="ds", table_id="t")
bq_table.schema = [SimpleNamespace(name="age", field_type="INTEGER")]