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(redshift): stop reporting a dropped table during row-count estimation (#100248)

Tom Owers1fb68f65a2e0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py
index f6a84d636a28..ed294d1149ab 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py
@@ -1416,6 +1416,14 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psyco
# `fetch_table_stats`.
logger.debug(f"get_rows_to_sync: no privilege to run count query, using 0 as rows to sync: {e}")
return 0
+ except psycopg.errors.UndefinedTable as e:
+ # The table existed when schema discovery ran but was dropped or renamed before this
+ # count query executed — the same already-known, non-actionable condition
+ # `get_non_retryable_errors` stops the sync for entirely. Row-count estimation is
+ # best-effort (the caller defaults to 0), so skip gracefully instead of reporting the
+ # non-actionable error to error tracking.
+ logger.debug(f"get_rows_to_sync: table no longer exists, using 0 as rows to sync: {e}")
+ return 0
except Exception as e:
logger.debug(f"get_rows_to_sync: Error: {e}. Using 0 as rows to sync", exc_info=e)
if "Remote request timeout" in str(e):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py
index 1f0fc6ccb981..8f01d8642693 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py
@@ -519,6 +519,19 @@ class TestGetRowsToSync:
assert impl.get_rows_to_sync(cursor, self._inner(), None, logger) == 0
mock_capture.assert_not_called()
+ def test_undefined_table_is_not_reported(self, impl, cursor, logger):
+ # The table can be dropped or renamed between schema discovery and this count query
+ # running. That's an expected, already-known customer/upstream condition (the overall
+ # sync's `get_non_retryable_errors` already stops retrying on "does not exist"), not an
+ # actionable bug — row-count estimation is best-effort (the caller defaults to 0), so skip
+ # gracefully without reporting it to error tracking.
+ cursor.execute.side_effect = psycopg.errors.UndefinedTable('relation "public.apps" does not exist')
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.redshift.redshift.capture_exception"
+ ) as mock_capture:
+ assert impl.get_rows_to_sync(cursor, self._inner(), None, logger) == 0
+ mock_capture.assert_not_called()
+
def test_remote_request_timeout_is_not_reported(self, impl, cursor, logger):
# A `Remote request timeout` (code 29150) is Redshift's leader node losing internal RPC
# contact with a compute node mid-query — a transient cluster-side hiccup, the same