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(data-warehouse): keep the schedule on for an automatic widen re-sync (#105116)

Tom Owers8878aabd259b
diff --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.py
index be1fe368ca94..5e1606439daf 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
@@ -33,6 +33,9 @@ from products.warehouse_sources.backend.temporal.data_imports.metrics import (
LOCK_TAKEOVER_LATEST_ERROR,
TERMINAL_JOB_STATUSES,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.auto_widen_resync import (
+ COLUMN_TYPE_WIDENED_KEY,
+)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.batch_consumer import (
MAX_ATTEMPTS,
POLL_INTERVAL_SECONDS,
@@ -338,11 +341,14 @@ class DeltaBatchConsumerAdapter:
if any(pattern in reason for pattern in DISABLE_SCHEMA_ERROR_PATTERNS):
try:
- await sync_to_async(_disable_schema_after_permanent_failure)(
- schema_id=batch.schema_id,
- team_id=batch.team_id,
- reason=reason,
- )
+ if not await sync_to_async(_auto_widen_reset_is_pending)(
+ schema_id=batch.schema_id, team_id=batch.team_id
+ ):
+ await sync_to_async(_disable_schema_after_permanent_failure)(
+ schema_id=batch.schema_id,
+ team_id=batch.team_id,
+ reason=reason,
+ )
except Exception as e:
# The run is already failed and the message recorded; a failed disable only means
# the next run retries, so log it rather than crashing the consumer.
@@ -811,10 +817,11 @@ class DeltaBatchConsumerAdapter:
limit exists to prevent.
- A deliberate stop (syncing turned off, the table deleted) is a decision to make
this run stop, so finishing the load would override it.
- - A permanent, unfixable failure (``DISABLE_SCHEMA_ERROR_PATTERNS``) already disabled
- the schema because the data itself cannot land, and a deletion failure
- (``DELETION_ERROR_PATTERNS``) means the schema or job row is gone; loading more in
- either case writes into a destination the run has already given up on.
+ - A permanent failure (``DISABLE_SCHEMA_ERROR_PATTERNS``) means the data itself cannot
+ land, and a deletion failure (``DELETION_ERROR_PATTERNS``) means the schema or job row
+ is gone; loading more in either case writes into a destination the run has already
+ given up on. A widening whose schedule stayed on is no exception: its next run resets
+ the table, so draining into the one this run gave up on is wasted either way.
``incremental`` is left because its next run continues from a staged cursor that
only promotes on a Completed job (``load/processor.py``). The job stays Failed here,
@@ -974,6 +981,27 @@ def _update_job_status_to_failed(*, job_id: str, team_id: int, error: str, run_u
pass
+def _auto_widen_reset_is_pending(*, schema_id: str, team_id: int) -> bool:
+ """Whether an automatic reset-and-resync is already stamped on this schema and not yet consumed.
+
+ ``maybe_schedule_auto_widen_resync`` stamps the reset for the *next* scheduled sync, so pausing
+ the schedule strands it. The stamp is the only reliable signal: only the first failure to
+ schedule one carries the reworded message, and the cooldown hands every later batch of the same
+ widening the manual-reset wording instead. The reset pops the marker when it runs, so a failure
+ after that disables as usual.
+ """
+ close_old_connections()
+
+ config = (
+ ExternalDataSchema.objects.filter(id=schema_id, team_id=team_id)
+ .values_list("sync_type_config", flat=True)
+ .first()
+ )
+ if not isinstance(config, dict):
+ return False
+ return bool(config.get("reset_pipeline")) and COLUMN_TYPE_WIDENED_KEY in config
+
+
def _disable_schema_after_permanent_failure(*, schema_id: str, team_id: int, reason: str) -> bool:
"""Stop a schema whose load failed permanently. Returns whether it flipped.
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.py
index 138aef17e6e5..02f4c5a70710 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
@@ -1503,12 +1503,34 @@ class TestFailRun:
with (
patch(f"{self.MODULE}.BatchQueue.fail_run", new_callable=AsyncMock),
patch(f"{self.MODULE}._update_job_status_to_failed"),
+ patch(f"{self.MODULE}._auto_widen_reset_is_pending", return_value=False),
patch(f"{self.MODULE}._disable_schema_after_permanent_failure") as mock_disable,
):
await consumer._fail_run(batch, reason=reason, conn=consumer._poll_conn)
assert mock_disable.called is expect_disabled
+ @pytest.mark.asyncio
+ async def test_a_widening_with_a_reset_already_stamped_keeps_its_schedule(self):
+ # Disabling pauses the schema's schedule, and the stamped reset only runs on the next
+ # scheduled sync — so disabling here strands the recovery the pipeline just promised.
+ consumer = _make_consumer()
+ batch = _make_batch()
+
+ with (
+ patch(f"{self.MODULE}.BatchQueue.fail_run", new_callable=AsyncMock),
+ patch(f"{self.MODULE}._update_job_status_to_failed"),
+ patch(f"{self.MODULE}._auto_widen_reset_is_pending", return_value=True),
+ patch(f"{self.MODULE}._disable_schema_after_permanent_failure") as mock_disable,
+ ):
+ await consumer._fail_run(
+ batch,
+ reason="Source column type changed: 'total_cost' has values that no longer fit its stored type int64",
+ conn=consumer._poll_conn,
+ )
+
+ assert mock_disable.called is False
+
@pytest.mark.asyncio
async def test_disable_failure_does_not_crash_the_consumer(self):
consumer = _make_consumer()