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): skip duplicate-key probe gracefully when a table is gone (#111658)

Tom Owers8cecb3f4a849
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 929b1c253db3..996e3e349beb 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
@@ -1559,6 +1559,14 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psyco
# error tracking. Mirrors `get_rows_to_sync`/`fetch_table_stats`.
logger.debug(f"has_duplicate_primary_keys: no privilege to run duplicate-key probe, skipping check: {e}")
return None
+ except psycopg.errors.UndefinedTable as e:
+ # The table existed when schema discovery ran but was dropped or renamed before this
+ # probe executed — the same already-known, non-actionable condition
+ # `get_non_retryable_errors` stops the sync for entirely. The duplicate-key probe is
+ # best-effort, so skip gracefully instead of reporting the expected error to error
+ # tracking. Mirrors `get_rows_to_sync`.
+ logger.debug(f"has_duplicate_primary_keys: table no longer exists, skipping check: {e}")
+ return None
except Exception as e:
# A Redshift system-requested query abort (error code 1020, "system requested abort")
# is the cluster's WLM/QMR cancelling the query — the same transient, non-actionable
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 4c501c4f90b1..15647d8dc320 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
@@ -1091,6 +1091,17 @@ class TestHasDuplicatePrimaryKeys:
assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is None
mock_capture.assert_not_called()
+ def test_undefined_table_is_not_reported(self, impl: Any, cursor: Any, logger: Any) -> None:
+ # The table was dropped or renamed between schema discovery and this probe running — a
+ # customer-side change, not an actionable bug. The probe is best-effort, so skip gracefully
+ # without reporting the expected error to error tracking.
+ cursor.execute.side_effect = psycopg.errors.UndefinedTable('relation "public.t" does not exist')
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.redshift.redshift.capture_exception"
+ ) as mock_capture:
+ assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is None
+ mock_capture.assert_not_called()
+
# ---------------------------------------------------------------------------
# Listing — exercise impl methods that take a real cursor mock