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): CDC improvements — fix dead orphan-slot sweeper (#64725)

Daniel RC7adbe096061f
diff --git a/posthog/temporal/data_imports/cdc/activities.py b/posthog/temporal/data_imports/cdc/activities.py
index 33263287e12d..7db1186a7ef9 100644
--- a/posthog/temporal/data_imports/cdc/activities.py
+++ b/posthog/temporal/data_imports/cdc/activities.py
@@ -24,6 +24,7 @@ from temporalio import activity
from posthog.settings import WAREHOUSE_SOURCES_DATABASE_URL
from posthog.temporal.common.activity_context import current_workflow_id, current_workflow_run_id
+from posthog.temporal.common.heartbeat_sync import HeartbeaterSync
from posthog.temporal.data_imports.cdc.adapters import cdc_supported_source_types, get_cdc_adapter
from posthog.temporal.data_imports.cdc.batcher import (
ChangeEventBatcher,
@@ -1001,101 +1002,109 @@ def cleanup_orphan_slots_activity() -> None:
log = logger.bind()
log.info("cleanup_orphan_slots_started")
- # Scope the query narrowly: only sources that have CDC enabled, have both a slot
- # and publication name set (otherwise there's nothing to clean up), and are of a
- # source type we know how to handle. We include deleted sources because the whole
- # point of this sweeper is to clean up slots for sources that were deleted.
- cdc_sources = list(
- ExternalDataSource.objects.filter(
- source_type__in=cdc_supported_source_types(),
- job_inputs__cdc_enabled=True,
- )
- .exclude(job_inputs__cdc_slot_name__isnull=True)
- .exclude(job_inputs__cdc_slot_name="")
- .exclude(job_inputs__cdc_publication_name__isnull=True)
- .exclude(job_inputs__cdc_publication_name="")
- )
-
- for source in cdc_sources:
- try:
- adapter = get_cdc_adapter(source)
- except ValueError:
- continue
+ # The CDC fields live in `job_inputs`, an EncryptedJSONField: every leaf value is
+ # Fernet-encrypted at rest, so `job_inputs__cdc_enabled=True` (and the slot/publication
+ # filters) can never match. We must scope by the unencrypted `source_type` column and
+ # decode each source's CDC config in Python. Deleted sources are included on purpose —
+ # cleaning up their orphaned slots is the whole point of this sweep.
+ sources = ExternalDataSource.objects.filter(source_type__in=cdc_supported_source_types()).iterator(chunk_size=100)
+
+ sources_checked = 0
+ # A single source's management connection (10s connect_timeout × several ops) can stall the
+ # loop, so heartbeat from a background thread rather than once per iteration — otherwise a
+ # stalled source would starve heartbeats and Temporal would kill the whole sweep.
+ with HeartbeaterSync(logger=log):
+ for source in sources:
+ try:
+ adapter = get_cdc_adapter(source)
+ except ValueError:
+ continue
- cdc_config = adapter.parse_cdc_config(source)
+ try:
+ cdc_config = adapter.parse_cdc_config(source)
+ except Exception:
+ log.exception("failed_to_parse_cdc_config", source_id=str(source.id))
+ continue
- source_log = log.bind(
- source_id=str(source.id),
- team_id=source.team_id,
- slot_name=cdc_config.slot_name,
- management_mode=cdc_config.management_mode,
- )
+ # Restore the original filter semantics on decrypted values: skip sources that
+ # don't have CDC enabled with both a slot and publication name to clean up.
+ if not (cdc_config.enabled and cdc_config.slot_name and cdc_config.publication_name):
+ continue
- # 1. Deleted sources — drop the Temporal schedule (always; PostHog-side)
- # and PostHog-managed slot/publication (only when we own them).
- if source.deleted:
- try:
- from products.data_warehouse.backend.data_load.service import delete_cdc_extraction_schedule
+ sources_checked += 1
- delete_cdc_extraction_schedule(str(source.id))
- except Exception:
- source_log.exception("failed_to_delete_cdc_extraction_schedule")
+ source_log = log.bind(
+ source_id=str(source.id),
+ team_id=source.team_id,
+ slot_name=cdc_config.slot_name,
+ management_mode=cdc_config.management_mode,
+ )
- if cdc_config.management_mode == "posthog":
- source_log.info("cleaning_up_deleted_source_slot")
+ # 1. Deleted sources — drop the Temporal schedule (always; PostHog-side)
+ # and PostHog-managed slot/publication (only when we own them).
+ if source.deleted:
try:
- with adapter.management_connection(source, connect_timeout=10) as conn:
- adapter.drop_resources(conn, cdc_config.slot_name, cdc_config.publication_name)
- except Exception:
- source_log.exception("failed_to_cleanup_deleted_source_slot")
- continue
+ from products.data_warehouse.backend.data_load.service import delete_cdc_extraction_schedule
- # 2. Active sources — check WAL lag
- try:
- with adapter.management_connection(source, connect_timeout=10) as conn:
- lag_bytes = adapter.get_lag_bytes(conn, cdc_config.slot_name)
- retention_cap_mb = adapter.get_retention_cap_mb(conn)
- except Exception:
- source_log.exception("failed_to_check_slot_lag")
- continue
+ delete_cdc_extraction_schedule(str(source.id))
+ except Exception:
+ source_log.exception("failed_to_delete_cdc_extraction_schedule")
+
+ if cdc_config.management_mode == "posthog":
+ source_log.info("cleaning_up_deleted_source_slot")
+ try:
+ with adapter.management_connection(source, connect_timeout=10) as conn:
+ adapter.drop_resources(conn, cdc_config.slot_name, cdc_config.publication_name)
+ except Exception:
+ source_log.exception("failed_to_cleanup_deleted_source_slot")
+ continue
- if lag_bytes is None:
- source_log.warning("slot_not_found_or_no_flush_lsn")
- continue
+ # 2. Active sources — check WAL lag
+ try:
+ with adapter.management_connection(source, connect_timeout=10) as conn:
+ lag_bytes = adapter.get_lag_bytes(conn, cdc_config.slot_name)
+ retention_cap_mb = adapter.get_retention_cap_mb(conn)
+ except Exception:
+ source_log.exception("failed_to_check_slot_lag")
+ continue
- lag_mb = lag_bytes / (1024 * 1024)
+ if lag_bytes is None:
+ source_log.warning("slot_not_found_or_no_flush_lsn")
+ continue
- critical_threshold_mb = cdc_config.lag_critical_threshold_mb
- if retention_cap_mb is not None:
- critical_threshold_mb = min(critical_threshold_mb, int(retention_cap_mb * RETENTION_CAP_SAFETY_FACTOR))
+ lag_mb = lag_bytes / (1024 * 1024)
- if lag_mb >= critical_threshold_mb:
- source_log.error(
- "slot_lag_critical",
- lag_mb=round(lag_mb, 1),
- threshold_mb=critical_threshold_mb,
- retention_cap_mb=retention_cap_mb,
- )
+ critical_threshold_mb = cdc_config.lag_critical_threshold_mb
+ if retention_cap_mb is not None:
+ critical_threshold_mb = min(critical_threshold_mb, int(retention_cap_mb * RETENTION_CAP_SAFETY_FACTOR))
- if cdc_config.management_mode == "posthog" and cdc_config.auto_drop_slot:
- source_log.warning("auto_dropping_slot_critical_lag")
- try:
- with adapter.management_connection(source, connect_timeout=10) as conn:
- adapter.drop_resources(conn, cdc_config.slot_name, cdc_config.publication_name)
+ if lag_mb >= critical_threshold_mb:
+ source_log.error(
+ "slot_lag_critical",
+ lag_mb=round(lag_mb, 1),
+ threshold_mb=critical_threshold_mb,
+ retention_cap_mb=retention_cap_mb,
+ )
+ if cdc_config.management_mode == "posthog" and cdc_config.auto_drop_slot:
+ source_log.warning("auto_dropping_slot_critical_lag")
+ try:
+ with adapter.management_connection(source, connect_timeout=10) as conn:
+ adapter.drop_resources(conn, cdc_config.slot_name, cdc_config.publication_name)
+
+ source.status = ExternalDataSource.Status.ERROR
+ source.save(update_fields=["status", "updated_at"])
+ except Exception:
+ source_log.exception("failed_to_auto_drop_slot")
+ elif cdc_config.management_mode == "self_managed":
source.status = ExternalDataSource.Status.ERROR
source.save(update_fields=["status", "updated_at"])
- except Exception:
- source_log.exception("failed_to_auto_drop_slot")
- elif cdc_config.management_mode == "self_managed":
- source.status = ExternalDataSource.Status.ERROR
- source.save(update_fields=["status", "updated_at"])
-
- elif lag_mb >= cdc_config.lag_warning_threshold_mb:
- source_log.warning(
- "slot_lag_warning",
- lag_mb=round(lag_mb, 1),
- threshold_mb=cdc_config.lag_warning_threshold_mb,
- )
- log.info("cleanup_orphan_slots_completed", sources_checked=len(cdc_sources))
+ elif lag_mb >= cdc_config.lag_warning_threshold_mb:
+ source_log.warning(
+ "slot_lag_warning",
+ lag_mb=round(lag_mb, 1),
+ threshold_mb=cdc_config.lag_warning_threshold_mb,
+ )
+
+ log.info("cleanup_orphan_slots_completed", sources_checked=sources_checked)
diff --git a/posthog/temporal/data_imports/cdc/tests/test_cleanup_orphan_slots.py b/posthog/temporal/data_imports/cdc/tests/test_cleanup_orphan_slots.py
new file mode 100644
index 000000000000..5ce50af2afb5
--- /dev/null
+++ b/posthog/temporal/data_imports/cdc/tests/test_cleanup_orphan_slots.py
@@ -0,0 +1,143 @@
+import uuid
+from contextlib import contextmanager
+
+import pytest
+from unittest.mock import MagicMock, patch
+
+from posthog.temporal.data_imports.cdc.activities import cleanup_orphan_slots_activity
+from posthog.temporal.data_imports.sources.postgres.cdc.config import PostgresCDCConfig
+
+from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
+
+pytestmark = pytest.mark.django_db
+
+
+def _create_source(team, *, deleted=False, job_inputs=None):
+ return ExternalDataSource.objects.create(
+ team_id=team.pk,
+ source_id=str(uuid.uuid4()),
+ connection_id=str(uuid.uuid4()),
+ status="Completed",
+ source_type="Postgres",
+ deleted=deleted,
+ job_inputs=job_inputs,
+ )
+
+
+def _cdc_job_inputs(*, enabled=True, management="posthog", auto_drop_slot=True, slot="posthog_slot", pub="posthog_pub"):
+ return {
+ "cdc_enabled": enabled,
+ "cdc_management_mode": management,
+ "cdc_auto_drop_slot": auto_drop_slot,
+ "cdc_slot_name": slot,
+ "cdc_publication_name": pub,
+ }
+
+
+def _mock_adapter(*, lag_bytes=0, retention_cap_mb=None):
+ """Adapter mock that decodes config for real (proving the encrypted-job_inputs path)
+ but stubs every database connection."""
+ adapter = MagicMock()
+ adapter.parse_cdc_config.side_effect = lambda source: PostgresCDCConfig.from_source(source)
+
+ @contextmanager
+ def _conn(source, connect_timeout=15):
+ yield MagicMock()
+
+ adapter.management_connection.side_effect = _conn
+ adapter.get_lag_bytes.return_value = lag_bytes
+ adapter.get_retention_cap_mb.return_value = retention_cap_mb
+ return adapter
+
+
+def _run(adapter):
+ with (
+ patch("posthog.temporal.data_imports.cdc.activities.activity") as mock_activity,
+ patch("posthog.temporal.data_imports.cdc.activities.HeartbeaterSync"),
+ patch("posthog.temporal.data_imports.cdc.activities.close_old_connections"),
+ patch("posthog.temporal.data_imports.cdc.activities.get_cdc_adapter", return_value=adapter),
+ patch("products.data_warehouse.backend.data_load.service.delete_cdc_extraction_schedule") as mock_delete,
+ ):
+ cleanup_orphan_slots_activity()
+ return mock_activity, mock_delete
+
+
+def test_encrypted_cdc_source_is_selected(team):
+ # Regression: cdc_enabled is encrypted at rest, so the old ORM filter never matched
+ # and the sweeper checked zero sources. It must now reach the active lag-check path.
+ _create_source(team, job_inputs=_cdc_job_inputs())
+ adapter = _mock_adapter(lag_bytes=0)
+
+ _run(adapter)
+
+ adapter.get_lag_bytes.assert_called_once()
+
+
+ "job_inputs",
+ [
+ None,
+ _cdc_job_inputs(enabled=False),
+ _cdc_job_inputs(slot=""),
+ _cdc_job_inputs(pub=""),
+ ],
+)
+def test_disabled_or_incomplete_sources_skipped(team, job_inputs):
+ _create_source(team, job_inputs=job_inputs)
+ adapter = _mock_adapter()
+
+ _run(adapter)
+
+ adapter.get_lag_bytes.assert_not_called()
+
+
+def test_deleted_posthog_managed_drops_resources_and_schedule(team):
+ _create_source(team, deleted=True, job_inputs=_cdc_job_inputs(management="posthog"))
+ adapter = _mock_adapter()
+
+ _, mock_delete = _run(adapter)
+
+ mock_delete.assert_called_once()
+ adapter.drop_resources.assert_called_once()
+ adapter.get_lag_bytes.assert_not_called()
+
+
+def test_deleted_self_managed_drops_schedule_but_not_slot(team):
+ _create_source(team, deleted=True, job_inputs=_cdc_job_inputs(management="self_managed"))
+ adapter = _mock_adapter()
+
+ _, mock_delete = _run(adapter)
+
+ mock_delete.assert_called_once()
+ adapter.drop_resources.assert_not_called()
+
+
+def test_critical_lag_posthog_auto_drop_drops_and_marks_error(team):
+ source = _create_source(team, job_inputs=_cdc_job_inputs(auto_drop_slot=True))
+ adapter = _mock_adapter(lag_bytes=5000 * 1024 * 1024) # 5000 MB > 2048 MB critical default
+
+ _run(adapter)
+
+ adapter.drop_resources.assert_called_once()
+ source.refresh_from_db()
+ assert source.status == ExternalDataSource.Status.ERROR
+
+
+def test_critical_lag_auto_drop_disabled_does_not_drop(team):
+ # cdc_auto_drop_slot stored as boolean False round-trips to "False"; str_to_bool must
+ # decode it as False so the safety net stays off.
+ _create_source(team, job_inputs=_cdc_job_inputs(auto_drop_slot=False))
+ adapter = _mock_adapter(lag_bytes=5000 * 1024 * 1024)
+
+ _run(adapter)
+
+ adapter.drop_resources.assert_not_called()
+
+
+def test_critical_lag_self_managed_never_drops(team):
+ _create_source(team, job_inputs=_cdc_job_inputs(management="self_managed"))
+ adapter = _mock_adapter(lag_bytes=5000 * 1024 * 1024)
+
+ _run(adapter)
+
+ adapter.drop_resources.assert_not_called()
diff --git a/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py b/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py
index 178ecef57e8a..dd8b44f17491 100644
--- a/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py
+++ b/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py
@@ -1510,10 +1510,10 @@ class TestCleanupOrphanSlotsRetentionCap:
def _setup(self, mock_get_adapter, MockSourceModel, lag_mb, cap_mb):
source = _make_source()
- qs = MockSourceModel.objects.filter.return_value
- qs.exclude.return_value.exclude.return_value.exclude.return_value.exclude.return_value = [source]
+ MockSourceModel.objects.filter.return_value.iterator.return_value = [source]
cdc_config = MagicMock()
+ cdc_config.enabled = True
cdc_config.slot_name = "posthog_slot"
cdc_config.publication_name = "posthog_pub"
cdc_config.management_mode = "posthog"
@@ -1528,10 +1528,14 @@ class TestCleanupOrphanSlotsRetentionCap:
mock_get_adapter.return_value = mock_adapter
return source, mock_adapter
+ @patch("posthog.temporal.data_imports.cdc.activities.HeartbeaterSync")
+ @patch("posthog.temporal.data_imports.cdc.activities.activity")
@patch("posthog.temporal.data_imports.cdc.activities.get_cdc_adapter")
@patch("posthog.temporal.data_imports.cdc.activities.ExternalDataSource")
@patch("posthog.temporal.data_imports.cdc.activities.close_old_connections")
- def test_retention_cap_lowers_critical_threshold(self, mock_close_conns, MockSourceModel, mock_get_adapter):
+ def test_retention_cap_lowers_critical_threshold(
+ self, mock_close_conns, MockSourceModel, mock_get_adapter, mock_activity, mock_heartbeater
+ ):
# Configured critical is 10240 MB, but the engine caps retention at 1000 MB:
# at 900 MB of lag (>= 80% of the cap) the sweeper must already act.
source, mock_adapter = self._setup(mock_get_adapter, MockSourceModel, lag_mb=900, cap_mb=1000)
@@ -1542,10 +1546,14 @@ class TestCleanupOrphanSlotsRetentionCap:
assert source.status is MockSourceModel.Status.ERROR
source.save.assert_called()
+ @patch("posthog.temporal.data_imports.cdc.activities.HeartbeaterSync")
+ @patch("posthog.temporal.data_imports.cdc.activities.activity")
@patch("posthog.temporal.data_imports.cdc.activities.get_cdc_adapter")
@patch("posthog.temporal.data_imports.cdc.activities.ExternalDataSource")
@patch("posthog.temporal.data_imports.cdc.activities.close_old_connections")
- def test_unlimited_retention_keeps_configured_threshold(self, mock_close_conns, MockSourceModel, mock_get_adapter):
+ def test_unlimited_retention_keeps_configured_threshold(
+ self, mock_close_conns, MockSourceModel, mock_get_adapter, mock_activity, mock_heartbeater
+ ):
source, mock_adapter = self._setup(mock_get_adapter, MockSourceModel, lag_mb=900, cap_mb=None)
cleanup_orphan_slots_activity()
diff --git a/posthog/temporal/data_imports/cdc/workflows.py b/posthog/temporal/data_imports/cdc/workflows.py
index b6edbb6fb34f..1f8671602a25 100644
--- a/posthog/temporal/data_imports/cdc/workflows.py
+++ b/posthog/temporal/data_imports/cdc/workflows.py
@@ -74,6 +74,7 @@ class CDCSlotCleanupWorkflow(PostHogWorkflow):
await workflow.execute_activity(
cleanup_orphan_slots_activity,
start_to_close_timeout=dt.timedelta(minutes=15),
+ heartbeat_timeout=dt.timedelta(minutes=2),
retry_policy=RetryPolicy(
initial_interval=dt.timedelta(seconds=30),
maximum_interval=dt.timedelta(seconds=300),
diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/config.py b/posthog/temporal/data_imports/sources/postgres/cdc/config.py
index 7b100e4f4223..f2fab1293cb6 100644
--- a/posthog/temporal/data_imports/sources/postgres/cdc/config.py
+++ b/posthog/temporal/data_imports/sources/postgres/cdc/config.py
@@ -12,6 +12,7 @@ import dataclasses
from typing import TYPE_CHECKING
from posthog.temporal.data_imports.cdc.types import CDCConfig, ManagementMode
+from posthog.utils import str_to_bool
if TYPE_CHECKING:
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
@@ -37,13 +38,13 @@ class PostgresCDCConfig(CDCConfig):
"self_managed" if ji.get("cdc_management_mode") == "self_managed" else "posthog"
)
return cls(
- enabled=bool(ji.get("cdc_enabled", False)),
+ enabled=str_to_bool(ji.get("cdc_enabled", False)),
slot_name=ji.get("cdc_slot_name") or "",
publication_name=ji.get("cdc_publication_name") or "",
management_mode=management_mode,
lag_warning_threshold_mb=int(ji.get("cdc_lag_warning_threshold_mb", DEFAULT_LAG_WARNING_THRESHOLD_MB)),
lag_critical_threshold_mb=int(ji.get("cdc_lag_critical_threshold_mb", DEFAULT_LAG_CRITICAL_THRESHOLD_MB)),
- auto_drop_slot=bool(ji.get("cdc_auto_drop_slot", True)),
+ auto_drop_slot=str_to_bool(ji.get("cdc_auto_drop_slot", True)),
consistent_point=ji.get("cdc_consistent_point"),
)
diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_cdc_config.py b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_cdc_config.py
new file mode 100644
index 000000000000..f32e0ce18f21
--- /dev/null
+++ b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_cdc_config.py
@@ -0,0 +1,92 @@
+import uuid
+
+import pytest
+
+from posthog.temporal.data_imports.sources.postgres.cdc.config import (
+ DEFAULT_LAG_CRITICAL_THRESHOLD_MB,
+ DEFAULT_LAG_WARNING_THRESHOLD_MB,
+ PostgresCDCConfig,
+)
+
+from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
+
+
+ "value,expected",
+ [
+ (True, True),
+ (False, False),
+ ("True", True),
+ ("False", False),
+ ("true", True),
+ (None, False),
+ ("__missing__", False),
+ ],
+)
+def test_from_dict_enabled_coercion(value, expected):
+ job_inputs = {} if value == "__missing__" else {"cdc_enabled": value}
+ assert PostgresCDCConfig.from_dict(job_inputs).enabled is expected
+
+
+ "value,expected",
+ [
+ (True, True),
+ (False, False),
+ ("True", True),
+ ("False", False),
+ ("true", True),
+ (None, False),
+ ("__missing__", True), # defaults to True when the key is absent
+ ],
+)
+def test_from_dict_auto_drop_slot_coercion(value, expected):
+ job_inputs = {} if value == "__missing__" else {"cdc_auto_drop_slot": value}
+ assert PostgresCDCConfig.from_dict(job_inputs).auto_drop_slot is expected
+
+
+def test_from_dict_defaults():
+ config = PostgresCDCConfig.from_dict(None)
+ assert config.enabled is False
+ assert config.slot_name == ""
+ assert config.publication_name == ""
+ assert config.management_mode == "posthog"
+ assert config.lag_warning_threshold_mb == DEFAULT_LAG_WARNING_THRESHOLD_MB
+ assert config.lag_critical_threshold_mb == DEFAULT_LAG_CRITICAL_THRESHOLD_MB
+ assert config.auto_drop_slot is True
+ assert config.consistent_point is None
+
+
+def test_from_dict_thresholds_coerce_stringified_ints():
+ config = PostgresCDCConfig.from_dict(
+ {"cdc_lag_warning_threshold_mb": "256", "cdc_lag_critical_threshold_mb": "1024"}
+ )
+ assert config.lag_warning_threshold_mb == 256
+ assert config.lag_critical_threshold_mb == 1024
+
+
+def test_from_source_round_trips_encrypted_booleans(team):
+ # job_inputs is an EncryptedJSONField: boolean leaves round-trip as "True"/"False"
+ # strings. from_source must decode them back to the right booleans.
+ source = ExternalDataSource.objects.create(
+ team_id=team.pk,
+ source_id=str(uuid.uuid4()),
+ connection_id=str(uuid.uuid4()),
+ status="Completed",
+ source_type="Postgres",
+ job_inputs={
+ "cdc_enabled": True,
+ "cdc_auto_drop_slot": False,
+ "cdc_slot_name": "posthog_slot",
+ "cdc_publication_name": "posthog_pub",
+ "cdc_management_mode": "posthog",
+ },
+ )
+ source.refresh_from_db()
+
+ config = PostgresCDCConfig.from_source(source)
+ assert config.enabled is True
+ assert config.auto_drop_slot is False
+ assert config.slot_name == "posthog_slot"
+ assert config.publication_name == "posthog_pub"
diff --git a/products/data_warehouse/backend/api/external_data_schema.py b/products/data_warehouse/backend/api/external_data_schema.py
index a4dbd850d632..ceb1d3fbc277 100644
--- a/products/data_warehouse/backend/api/external_data_schema.py
+++ b/products/data_warehouse/backend/api/external_data_schema.py
@@ -24,6 +24,7 @@ from posthog.temporal.data_imports.sources.common.sql import (
filter_dwh_columns_by_enabled_columns as _filter_dwh_columns_by_enabled_columns,
validate_and_coerce_row_filters,
)
+from posthog.utils import str_to_bool
from products.data_warehouse.backend.data_load.service import (
cancel_external_data_workflow,
@@ -1139,7 +1140,9 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
status=status.HTTP_400_BAD_REQUEST, data={"message": f"Schema with name {instance.name} not found"}
)
- source_cdc_enabled = bool(source.job_inputs.get("cdc_enabled"))
+ # job_inputs is an EncryptedJSONField: booleans round-trip as "True"/"False"
+ # strings, so bool(...) would treat "False" as truthy. str_to_bool decodes both.
+ source_cdc_enabled = str_to_bool(source.job_inputs.get("cdc_enabled"))
cdc_available = schema.supports_cdc if is_cdc_enabled_for_team(self.team) and source_cdc_enabled else None
data = {