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(warehouse-sources): skip the audit read when marking CDC schemas running (#100753)

Tom Owersaa863e847e82
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py
index 015301ac84c7..74bf25ee775a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py
@@ -1030,7 +1030,10 @@ class CDCExtractActivity:
"""Mark CDC schemas as Running at the start."""
for schema in self.cdc_schemas:
schema.status = ExternalDataSchema.Status.RUNNING
- schema.save(update_fields=["status", "updated_at"])
+ # skip_activity_log avoids the extra _get_before_update SELECT, which raises
+ # OperationalError when the transaction pooler has dropped the connection since the
+ # last activity attempt — see ExternalDataSchema.save.
+ schema.save(update_fields=["status", "updated_at"], skip_activity_log=True)
def _reconcile_orphaned_prior_jobs(self) -> None:
"""Finalize this source's prior RUNNING jobs that were stranded mid-run.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py
index b7440b3da5d9..5dec8e963726 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py
@@ -412,6 +412,22 @@ class TestBackpressureGuard:
assert act.reader is None
+class TestMarkSchemasRunning:
+ def test_skips_activity_log_to_avoid_stale_pooled_connection(self):
+ # A previous attempt may have left the pooler connection stale; the extra
+ # _get_before_update SELECT that activity logging would run raises OperationalError
+ # ("the connection is closed") on it, failing the run before extraction even starts.
+ source = _make_source()
+ act = _make_extract_activity(source)
+ schema = _make_schema("users", source=source)
+ act.cdc_schemas = [schema]
+
+ act._mark_schemas_running()
+
+ assert schema.status == ExternalDataSchema.Status.RUNNING
+ schema.save.assert_called_once_with(update_fields=["status", "updated_at"], skip_activity_log=True)
+
+
class TestFlushDeferredRuns:
@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.PostgresProducer")
def test_sends_kafka_messages_for_deferred_runs(self, MockProducer):