: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): skip dup-PK check on system-requested query abort (#64160)
Tom Owers1bb14300113e
diff --git a/posthog/temporal/data_imports/sources/redshift/redshift.py b/posthog/temporal/data_imports/sources/redshift/redshift.pyindex 9d8099f82f9c..3c9d9a1c6810 100644--- a/posthog/temporal/data_imports/sources/redshift/redshift.py+++ b/posthog/temporal/data_imports/sources/redshift/redshift.py@@ -742,6 +742,15 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psycoexcept psycopg.errors.QueryCanceled:raiseexcept 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+ # class as `QueryCanceled`, which psycopg surfaces here as `InternalError_` rather than+ # `QueryCanceled`. The duplicate-PK check is best-effort (the caller defaults to no+ # duplicates), so skip gracefully instead of reporting an expected, non-actionable error+ # to error tracking. Mirrors the graceful-skip probes elsewhere in this driver.+ if "system requested abort" in str(e):+ logger.debug(f"has_duplicate_primary_keys: query aborted by Redshift, skipping check: {e}")+ return Falsecapture_exception(e)return Falsediff --git a/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py b/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.pyindex f62b96a20742..9a0d633d713f 100644--- a/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py+++ b/posthog/temporal/data_imports/sources/redshift/tests/test_redshift.py@@ -401,7 +401,21 @@ class TestHasDuplicatePrimaryKeys:def test_returns_false_on_exception(self, impl, cursor, logger):cursor.execute.side_effect = RuntimeError("boom")- assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is False+ with patch("posthog.temporal.data_imports.sources.redshift.redshift.capture_exception") as mock_capture:+ assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is False+ mock_capture.assert_called_once()++ def test_system_requested_abort_is_not_reported(self, impl, cursor, logger):+ # Redshift WLM/QMR aborts (code 1020, "system requested abort") surface as `InternalError_`+ # and are expected, non-actionable noise — skip gracefully without reporting to error tracking.+ abort_message = (+ "abort query\nDETAIL: \n error: abort query\n code: 1020\n"+ " context: system requested abort\n location: queryabort.hpp:103\n"+ )+ cursor.execute.side_effect = psycopg.errors.InternalError(abort_message)+ with patch("posthog.temporal.data_imports.sources.redshift.redshift.capture_exception") as mock_capture:+ assert impl.has_duplicate_primary_keys(cursor, "public", "t", ["id"], logger) is False+ mock_capture.assert_not_called()# ---------------------------------------------------------------------------