: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(data-imports): stop tracking expected schema-type-change failures (#73133)
Tom Owers1b41190fecb7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.pyindex aebc6773ad61..3d1b160ea017 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py@@ -241,6 +241,14 @@ class BatchConsumerAdapter(Protocol):the run's terminal state."""...+ def is_expected_user_error(self, err: Exception) -> bool:+ """Whether the failure is an expected upstream/customer condition rather than a bug in+ our pipeline (e.g. a source column whose type changed and no longer fits the stored+ type — only a reset and full re-sync resolves it). The run still fails with the error's+ actionable message, but the engine keeps these out of error tracking. Orthogonal to+ ``is_retryable_error``: an error can be both non-retryable and expected."""+ ...+async def after_batch_processed(self,conn: psycopg.AsyncConnection[Any],@@ -923,14 +931,25 @@ class BatchConsumer:if not self._adapter.is_retryable_error(err):# Deterministic failures do not benefit from retrying. Preserve their# messages, except for explicitly classified permanent apply errors.- logger.exception(- self._event("batch_failed_non_retryable"),- batch_id=batch.id,- run_uuid=batch.run_uuid,- attempt=attempt,- )- capture_exception(err)reason = f"permanent apply error: {err}" if isinstance(err, PermanentBatchApplyError) else str(err)+ if self._adapter.is_expected_user_error(err):+ # Expected upstream/customer condition — the run fails with an actionable+ # message; there is nothing for us to fix, so keep it out of error tracking.+ logger.warning(+ self._event("batch_failed_expected_user_error"),+ batch_id=batch.id,+ run_uuid=batch.run_uuid,+ attempt=attempt,+ error=str(err),+ )+ else:+ logger.exception(+ self._event("batch_failed_non_retryable"),+ batch_id=batch.id,+ run_uuid=batch.run_uuid,+ attempt=attempt,+ )+ capture_exception(err)await self._fail_run(batch, reason=reason, conn=lock_conn)elif attempt >= self._config.max_attempts:reason = f"max retries exceeded: {err}"diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.pyindex 0d1d0bc17a6e..853351dfed0d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py@@ -475,6 +475,11 @@ class DuckgresBatchConsumerAdapter:def is_retryable_error(self, err: Exception) -> bool:return not isinstance(err, PermanentBatchApplyError)+ def is_expected_user_error(self, err: Exception) -> bool:+ # The duckgres sink applies already-validated Delta batches; it has no expected+ # customer-actionable failures of its own to keep out of error tracking.+ return False+class DuckgresBatchConsumer(SharedBatchConsumer):"""The shared engine plus the sink's lease-safety overrides, kept out of thediff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.pyindex 74d63a414858..51d1f6283da8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py@@ -83,6 +83,16 @@ NON_RETRYABLE_ERROR_PATTERNS: tuple[str, ...] = ("ExternalDataJob matching query does not exist",)+# Subset of the non-retryable errors that are expected upstream/customer conditions rather than+# pipeline bugs. The run still fails with an actionable message, but the engine skips+# error-tracking capture for these so they don't drown real bugs. Kept deliberately narrow.+EXPECTED_USER_ERROR_PATTERNS: tuple[str, ...] = (+ # a source column's type changed upstream and no longer fits the stored Delta column+ # (SchemaColumnTypeChangedException) — delta-rs can't widen in place, so the fix is a+ # user-driven reset and full re-sync, not a code change+ "Source column type changed",+)+# How long an "alive" job-status lookup stays cached before re-checking the app DB.# Dead results never expire — a terminal job never comes back to life — and eviction# drops alive entries first, so a dead verdict survives until the cache overflows@@ -463,6 +473,10 @@ class DeltaBatchConsumerAdapter:message = str(err)return not any(pattern in message for pattern in NON_RETRYABLE_ERROR_PATTERNS)+ def is_expected_user_error(self, err: Exception) -> bool:+ message = str(err)+ return any(pattern in message for pattern in EXPECTED_USER_ERROR_PATTERNS)+async def after_batch_processed(self,conn: psycopg.AsyncConnection[Any],diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.pyindex 2c33444d26d5..61e2411f53d6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py@@ -176,6 +176,37 @@ class TestProcessSingle:states = [call[1]["job_state"] for call in mock_status.call_args_list]assert SourceBatchStatus.State.WAITING_RETRY not in states+ @pytest.mark.parametrize(+ ("message", "expect_capture"),+ [+ # Expected upstream/customer condition (a source column's type changed and no longer+ # fits the stored type): the run fails with an actionable message but stays out of+ # error tracking.+ ("Source column type changed: 'price' has values that no longer fit its stored type int64", False),+ # A genuine non-retryable failure must still surface so real bugs aren't hidden.+ ("20009.59 is too large to store in a Decimal128 of precision 24.", True),+ ],+ )+ @pytest.mark.asyncio+ async def test_expected_user_error_skips_error_tracking(self, message: str, expect_capture: bool):+ consumer = _make_consumer(max_attempts=3)+ batch = _make_batch(latest_attempt=0)+ consumer._process_batch = AsyncMock(side_effect=ValueError(message))++ with (+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.BatchQueue.update_status_unless_failed",+ new_callable=AsyncMock,+ ),+ patch.object(consumer, "_fail_run", new_callable=AsyncMock) as mock_fail,+ patch.object(batch_consumer_module, "capture_exception") as mock_capture,+ ):+ await consumer._process_single(batch)++ mock_fail.assert_called_once()+ assert mock_fail.call_args[1]["reason"] == message # run still fails with the actionable message+ assert mock_capture.called is expect_capture+@pytest.mark.asyncioasync def test_max_attempts_exceeded_fails_run(self):consumer = _make_consumer(max_attempts=3)