: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(redshift): stop duplicate-key probe reporting permission denials (#101917)
Tom Owers3db8589a7a66
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.pyindex b92c0c8cea75..1909bf8d227c 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@@ -1506,6 +1506,15 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psyco# Propagate it so the activity's retry path handles it; these are transient and stay# retryable. Mirrors the equivalent Postgres source.raise+ except psycopg.errors.InsufficientPrivilege as e:+ # The connecting role can SELECT the table itself but Redshift also gates a+ # materialized view's base relation(s) separately (SQLSTATE 42501) — the same+ # permission gap `get_non_retryable_errors` stops the sync for. The duplicate-key+ # probe is best-effort and already treats "could not run" as inconclusive rather than+ # clean, so skip gracefully instead of reporting the expected, non-actionable error to+ # 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 Noneexcept 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-actionablediff --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.pyindex 567485697342..edd6515f2c00 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@@ -1038,6 +1038,19 @@ class TestHasDuplicatePrimaryKeys:assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is Nonemock_capture.assert_not_called()+ def test_insufficient_privilege_is_not_reported(self, impl: Any, cursor: Any, logger: Any) -> None:+ # The connecting role lacks SELECT on the relation (or a materialized view's base table) —+ # a customer permission-config issue, 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.InsufficientPrivilege(+ 'permission denied for materialized view base relation "some_mv"'+ )+ 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