: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 best-effort row-size sampling failures (#63916)
Tom Owers5a50665fce2e
diff --git a/posthog/temporal/data_imports/sources/redshift/redshift.py b/posthog/temporal/data_imports/sources/redshift/redshift.pyindex f42319843c4e..b9a3f40f649f 100644--- a/posthog/temporal/data_imports/sources/redshift/redshift.py+++ b/posthog/temporal/data_imports/sources/redshift/redshift.py@@ -894,6 +894,10 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psycoalready bound — no separate `inner_query_args` is interpolatedhere, mirroring how the rest of the Redshift driver buildsqueries.++ Best-effort only: Redshift rejects the `pg_column_size(t)` whole-row reference, so this+ currently returns None on every table and the caller falls back to the default chunk size.+ Failures are swallowed rather than reported — see the except block below."""try:query = sql.SQL("""@@ -915,8 +919,13 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psycoexcept psycopg.errors.QueryCanceled:raiseexcept Exception as e:+ # Best-effort sampling: any failure falls back to the default chunk size, so it must not+ # be reported to error tracking. Redshift has no portable whole-row size — `pg_column_size(t)`+ # (like Postgres' `octet_length(t::text)`) relies on a composite whole-row reference that+ # Redshift rejects with `UndefinedColumn: column "t" does not exist in t`, so this fails on+ # every table. Mirrors the sibling Postgres `_get_table_chunk_size` and `_explain_query` here,+ # both of which treat this as expected, non-actionable noise.logger.debug(f"fetch_average_row_size: Error: {e}", exc_info=e)- capture_exception(e)return None# ------------------------------------------------------------------diff --git a/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py b/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.pyindex 971257f2564a..cc3c7a0c1d08 100644--- a/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py+++ b/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py@@ -360,6 +360,18 @@ class TestFetchAverageRowSize:cursor.execute.side_effect = [None, RuntimeError("boom")]assert impl.fetch_average_row_size(cursor, "public", "t", self._inner(), None, logger) is None+ def test_does_not_report_whole_row_reference_failure(self, impl, cursor, logger):+ # Redshift rejects the `pg_column_size(t)` whole-row reference with this exact error on every+ # table. It's a best-effort probe that falls back to the default chunk size, so it must not be+ # reported to error tracking (the source of the noise this fix addresses).+ cursor.execute.side_effect = [None, psycopg.errors.UndefinedColumn('column "t" does not exist in t')]++ with patch("posthog.temporal.data_imports.sources.redshift.redshift.capture_exception") as mock_capture:+ result = impl.fetch_average_row_size(cursor, "public", "t", self._inner(), None, logger)++ assert result is None+ mock_capture.assert_not_called()+class TestHasDuplicatePrimaryKeys:def test_returns_false_when_no_pks(self, impl, cursor, logger):