: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(postgres): treat missing-table partition probe as non-capturing noise (#63830)
Tom Owersf055d53297cb
diff --git a/posthog/temporal/data_imports/sources/postgres/postgres.py b/posthog/temporal/data_imports/sources/postgres/postgres.pyindex 5a6d858af757..2b888b988043 100644--- a/posthog/temporal/data_imports/sources/postgres/postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/postgres.py@@ -1495,6 +1495,15 @@ def _get_partition_settings(cursor.execute(query)except psycopg.errors.QueryCanceled:raise+ except psycopg.errors.UndefinedTable as e:+ # The selected table was dropped or renamed in the source between schema discovery and+ # this best-effort partition-sizing probe. That's a user/upstream condition we already+ # tolerate here (return None -> no partitioning), and the real extraction query — which+ # shares this FROM clause — hits the same missing relation and surfaces it through the+ # normal non-retryable path ("does not exist"). Capturing it here too would only flood+ # error tracking with handled duplicates, so mirror `_get_rows_to_sync` and log at debug.+ logger.debug(f"_get_partition_settings: table does not exist, returning None: {e}")+ return Noneexcept Exception as e:# Partition sizing is best-effort: on failure we return None and the sync proceeds# unpartitioned. Two handled conditions must not flood error tracking:diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 454745f0688a..1651a16baa5e 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -2026,6 +2026,22 @@ class TestGetPartitionSettings:assert result is not Noneassert result.partition_size > 0+ def test_missing_table_falls_back_to_none_without_capturing(self):+ # The selected table was dropped/renamed before this best-effort probe, so psycopg raises+ # UndefinedTable (42P01). The real extraction query surfaces "does not exist" through the+ # non-retryable path, so this helper must degrade quietly (None) instead of flooding error+ # tracking with a handled duplicate.+ logger = structlog.get_logger()++ cursor = mock.MagicMock()+ cursor.execute.side_effect = psycopg.errors.UndefinedTable('relation "public.store_source" does not exist')++ with patch("posthog.temporal.data_imports.sources.postgres.postgres.capture_exception") as mock_capture:+ result = _get_partition_settings(cast(Any, cursor), "public", "store_source", logger, is_partitioned=False)++ assert result is None+ mock_capture.assert_not_called()+def test_reuses_passed_is_partitioned_flag(self):# When the caller already knows the table is partitioned, skip re-detecting it.logger = structlog.get_logger()