: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 reporting permission-denied row-count probes as bugs (#75841)
Tom Owersc49d31052352
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 98ee3b3df9dc..f199537a1446 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@@ -887,6 +887,14 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psycoreturn int(row[0] or 0)except psycopg.errors.QueryCanceled:raise+ except psycopg.errors.InsufficientPrivilege as e:+ # The connecting role can SELECT the table itself but Redshift also gates access to a+ # materialized view's base relation(s) separately (SQLSTATE 42501). Row-count+ # estimation is best-effort (the caller defaults to 0), so skip gracefully instead of+ # reporting the expected, non-actionable error to error tracking. Mirrors+ # `fetch_table_stats`.+ logger.debug(f"get_rows_to_sync: no privilege to run count query, using 0 as rows to sync: {e}")+ return 0except Exception as e:logger.debug(f"get_rows_to_sync: Error: {e}. Using 0 as rows to sync", exc_info=e)capture_exception(e)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.pyindex 4ed99c7b0ce4..951b85e353ed 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py@@ -161,7 +161,21 @@ class RedshiftSource(SQLSource[RedshiftSourceConfig], SSHTunnelMixin, ValidateDa"TemporaryFileSizeExceedsLimitException": None,"Name or service not known": None,"Network is unreachable": None,+ # `InsufficientPrivilege` is the psycopg exception class name. It only appears once+ # Temporal wraps the activity failure (`ApplicationError` stringifies as+ # "InsufficientPrivilege: ..."), so it matches at the workflow layer but NOT in the+ # activity-level check, where `error_msg = str(e)` is the raw psycopg message —+ # Redshift's SQLSTATE 42501 text "permission denied for ...". Match that message+ # substring too so the role-lacks-SELECT case (including a materialized view whose+ # base relation isn't separately granted) is caught at both layers instead of burning+ # the activity's full retry budget on a denial that can't resolve itself."InsufficientPrivilege": None,+ "permission denied for": (+ "PostHog's database role isn't allowed to read one or more of the tables you selected to sync "+ '(Redshift reported "permission denied"). If this is a materialized view, Redshift also '+ "requires the connecting role to have SELECT on its underlying base table(s), not just the "+ "view. Grant the connecting role SELECT on those tables, then re-enable the sync."+ ),"No route to host": None,"password authentication failed connection": None,"connection timeout expired": None,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.pyindex 731109d0e924..99f993bd4b87 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@@ -360,6 +360,21 @@ class TestGetRowsToSync:with pytest.raises(TemporaryFileSizeExceedsLimitException):impl.get_rows_to_sync(cursor, self._inner(), None, logger)+ def test_permission_denied_on_materialized_view_is_not_reported(self, impl, cursor, logger):+ # A materialized view's base relation can be denied even when the view itself is+ # selectable. That's an expected customer permission-config issue, not an actionable bug —+ # row-count estimation is best-effort (the caller defaults to 0), so skip gracefully+ # without reporting the non-actionable error to error tracking (the source of the reported+ # noise).+ cursor.execute.side_effect = psycopg.errors.InsufficientPrivilege(+ 'permission denied for materialized view base relation "Payment_Actions"'+ )+ 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()+class TestFetchTableStats:def test_returns_none_when_no_row(self, impl, cursor, logger):@@ -838,6 +853,17 @@ class TestRedshiftSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable+ def test_permission_denied_raw_message_is_non_retryable(self):+ # The activity-level check matches the raw `str(exception)`, which for a psycopg+ # `InsufficientPrivilege` never contains the class name — only the `InsufficientPrivilege`+ # key (which only matches once Temporal's `ApplicationError` wraps the failure with the+ # class name) would miss this, letting the activity burn its full retry budget on a+ # permission denial that can't resolve itself.+ error_msg = 'permission denied for materialized view base relation "Payment_Actions"'+ non_retryable = RedshiftSource().get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable+class TestRedshiftValidateCredentials:def test_server_without_ssl_returns_friendly_error_without_capturing(self, mocker):