Skip to content

: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.

fix(mysql): stop capturing best-effort partition-sizing errors (#67237)

Tom Owers81a97cda51ac
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
index 1fd32a118bd3..035480675ede 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
@@ -308,8 +308,13 @@ class SQLSourceImplementation(Generic[ConfigT, ConnT, CursorT], ABC):
try:
stats = self.fetch_table_stats(cursor, schema, table_name, logger)
except Exception as e:
+ # Partition sizing is a best-effort optimization: returning None just falls back to
+ # default partition settings and the sync proceeds. Any genuine problem (missing table,
+ # permissions) resurfaces in the real extraction query and is classified through the
+ # normal retryable/non-retryable path, while transient connection drops here stay
+ # retryable there too. Capturing it would only flood error tracking with handled
+ # duplicates, so log at debug and fall back.
logger.debug(f"get_partition_settings: Error fetching stats: {e}. Returning None", exc_info=e)
- capture_exception(e)
return None
if stats is None or stats.row_count == 0:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
index ad16ccaf1e46..dd3429f854c3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
@@ -13,7 +13,7 @@ from contextlib import contextmanager
from typing import Any
import pytest
-from unittest.mock import MagicMock
+from unittest.mock import MagicMock, patch
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import (
SourceInputs,
@@ -94,9 +94,14 @@ class TestGetPartitionSettings:
def test_returns_none_when_fetch_raises(self, logger):
impl = _FakeImplementation(raises_on_stats=True)
- assert impl.get_partition_settings(MagicMock(), "db", "t", logger) is None
+ module = "products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.implementation"
+ with patch(f"{module}.capture_exception") as mock_capture:
+ assert impl.get_partition_settings(MagicMock(), "db", "t", logger) is None
# We still called through to the driver hook.
assert len(impl.fetch_table_stats_calls) == 1
+ # Best-effort probe: a raised stats query must not flood error tracking — it degrades to
+ # None here and resurfaces in the real extraction query if it's a genuine problem.
+ mock_capture.assert_not_called()
def test_single_partition_fallback_when_partition_count_is_zero(self, logger):
# Tiny table: 100 bytes, 2 rows → avg_row_size = 50 → partition_size huge