: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-warehouse): turn off syncing when deleting a synced table (#117724)
posthog[bot]06367897b5bf
diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsxindex 1b260fa57fa7..5bd874f9f05b 100644--- a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx+++ b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx@@ -1390,9 +1390,11 @@ function DangerZoneSection({onClick={() => {LemonDialog.open({title: `Delete ${schema.table?.name ?? schema.name} from PostHog?`,- description: source?.source_type- ? `The data in ${source.source_type} will not be touched.`- : undefined,+ description: `This also turns off syncing for the table.${+ source?.source_type+ ? ` The data in ${source.source_type} will not be touched.`+ : ''+ }`,primaryButton: {children: 'Delete',status: 'danger',diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsxindex cdee37625b75..16c15cd9954f 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx@@ -920,7 +920,7 @@ function SchemaBulkActions({LemonDialog.open({title: `Delete ${pluralize(count, 'table', 'tables')} from PostHog?`,description:- 'Removes the synced tables from PostHog. The data in the source is not touched.',+ 'Removes the synced tables from PostHog and turns off syncing for them. The data in the source is not touched.',primaryButton: {children: 'Delete from PostHog',status: 'danger',@@ -1091,9 +1091,11 @@ function SchemaRowMore({onClick={() => {LemonDialog.open({title: `Delete ${schema.table?.name ?? schema.name} from PostHog?`,- description: source?.source_type- ? `The data in ${source.source_type} will not be touched.`- : undefined,+ description: `This also turns off syncing for the table.${+ source?.source_type+ ? ` The data in ${source.source_type} will not be touched.`+ : ''+ }`,primaryButton: {children: 'Delete',status: 'danger',diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.tsindex c7787b78cb21..e85c0920b6d1 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts@@ -1560,6 +1560,7 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([return}clonedSource.schemas[schemaIndex].table = undefined+ clonedSource.schemas[schemaIndex].should_sync = falseclonedSource.schemas[schemaIndex].status = undefinedclonedSource.schemas[schemaIndex].last_synced_at = undefinedactions.loadSourceSuccess(clonedSource)diff --git a/products/warehouse_sources/backend/presentation/views/external_data_schema.py b/products/warehouse_sources/backend/presentation/views/external_data_schema.pyindex 67299815fb77..79349256a90b 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_schema.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_schema.py@@ -2343,6 +2343,13 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):instance.save(update_fields=["should_sync", "updated_at"])return Response(status=status.HTTP_200_OK)+ # Turn syncing off first, or the next scheduled run rebuilds the deleted table. The serializer+ # also pauses the schedule and takes a CDC table out of the publication. It runs even when+ # should_sync is already false, so a retry after a failed pause pauses the schedule again.+ serializer = self.get_serializer(instance, data={"should_sync": False}, partial=True)+ serializer.is_valid(raise_exception=True)+ instance = serializer.save()+instance.delete_table()return Response(status=status.HTTP_200_OK)diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py b/products/warehouse_sources/backend/tests/api/test_external_data_schema.pyindex a2b3fdb4900b..52a49ae72f59 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_schema.py@@ -3369,6 +3369,47 @@ class TestUpdateExternalDataSchema:assert schema.table_id == table.idassert DataWarehouseTable.raw_objects.get(pk=table.pk).deleted is True+ def test_delete_data_turns_off_sync_and_pauses_schedule(self, team, user, client: HttpClient, temporal):+ client.force_login(user)+ source = ExternalDataSource.objects.create(+ team=team,+ source_id=str(uuid.uuid4()),+ connection_id=str(uuid.uuid4()),+ destination_id=str(uuid.uuid4()),+ status=ExternalDataSource.Status.RUNNING,+ source_type=ExternalDataSourceType.STRIPE,+ job_inputs={},+ )+ table = DataWarehouseTable.objects.create(+ name="stripe_customer",+ format=DataWarehouseTable.TableFormat.Parquet,+ team=team,+ external_data_source=source,+ )+ schema = ExternalDataSchema.objects.create(+ team=team,+ source=source,+ name="Customer",+ should_sync=True,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ table=table,+ )++ views = "products.warehouse_sources.backend.presentation.views.external_data_schema"+ with (+ mock.patch(f"{views}.external_data_workflow_exists", return_value=True),+ mock.patch(f"{views}.pause_external_data_schedule") as mock_pause,+ mock.patch("products.data_warehouse.backend.facade.api.get_s3_client"),+ ):+ response = client.delete(f"/api/environments/{team.pk}/external_data_schemas/{schema.id}/delete_data")++ assert response.status_code == 200+ mock_pause.assert_called_once_with(str(schema.id))+ schema.refresh_from_db()+ assert schema.should_sync is False+ assert schema.table_id is None+ assert DataWarehouseTable.raw_objects.get(pk=table.pk).deleted is True+def test_update_schema_change_sync_type_with_invalid_type(self, team, user, client: HttpClient, temporal):client.force_login(user)source_id = create_external_data_source_ok(client, team.pk)diff --git a/products/warehouse_sources/mcp/tools.yaml b/products/warehouse_sources/mcp/tools.yamlindex d5c1809a86e3..d113055c9696 100644--- a/products/warehouse_sources/mcp/tools.yaml+++ b/products/warehouse_sources/mcp/tools.yaml@@ -140,8 +140,10 @@ tools:idempotent: truetitle: Delete synced table datadescription: >- Delete the synced table data from PostHog but keep the schema entry. The schema remains visible in the- source and can be re-synced. Use this to clear stale or corrupt data before triggering a fresh sync.+ Delete the synced table data from PostHog but keep the schema entry. This also sets should_sync to false and+ pauses the schedule, so the next scheduled run does not rebuild the table. To sync the table again, set+ should_sync to true with 'external-data-schemas-partial-update', then call 'external-data-schemas-reload'.+ To clear stale or corrupt data and keep syncing on, use 'external-data-schemas-resync' instead.external-data-schemas-destinations-retrieve:operation: external_data_schemas_destinations_retrieveenabled: truediff --git a/products/warehouse_sources/skills/diagnosing-failed-warehouse-syncs/SKILL.md b/products/warehouse_sources/skills/diagnosing-failed-warehouse-syncs/SKILL.mdindex fe493107ba37..8ec099dd300a 100644--- a/products/warehouse_sources/skills/diagnosing-failed-warehouse-syncs/SKILL.md+++ b/products/warehouse_sources/skills/diagnosing-failed-warehouse-syncs/SKILL.md@@ -152,7 +152,8 @@ The recovery action depends on root cause, not just status. Match the user's sit**G. Table data is corrupt but you want to keep the schema config**-- Action: `external-data-schemas-delete-data` to drop the synced table but preserve the schema entry. Next reload+- Action: `external-data-schemas-delete-data` to drop the synced table but preserve the schema entry. It also turns+ syncing off, so set `should_sync: true` with `external-data-schemas-partial-update`, then reload. The reloadre-imports from scratch without losing the configured sync_type/incremental_field.**H. Billing limit**@@ -226,7 +227,7 @@ Agent:as a first-try for transient errors.- **Delete-data preserves config.** When a user says "I just want to start this table over from scratch", prefer`delete-data` + `reload` over `resync` + new schema entry — it keeps the configured sync_type / incremental_field- / PK setup.+ / PK setup. `delete-data` turns syncing off, so set `should_sync: true` before the reload.- **A failure can belong to a destination, not the source.** Some projects sync a source to their own database aswell as to PostHog. When they do, `latest_error` is prefixed with the destination's name, e.g.`customer postgres: connection refused`. That is the customer's database refusing the write, not the source failingdiff --git a/products/warehouse_sources/skills/tuning-incremental-sync-config/SKILL.md b/products/warehouse_sources/skills/tuning-incremental-sync-config/SKILL.mdindex 1b0451c5e06b..6185ac32705b 100644--- a/products/warehouse_sources/skills/tuning-incremental-sync-config/SKILL.md+++ b/products/warehouse_sources/skills/tuning-incremental-sync-config/SKILL.md@@ -150,8 +150,9 @@ When the change invalidates data, the clean flow is:2. Warn the user this is destructive3. `external-data-schemas-resync` to wipe and re-import under the new config-Or equivalently, `external-data-schemas-delete-data` → `external-data-schemas-reload`. `delete-data` + `reload` is-cleaner when the table is large and the user wants to start from zero.+Or `external-data-schemas-delete-data` → `external-data-schemas-partial-update` with `should_sync: true` →+`external-data-schemas-reload`. `delete-data` turns syncing off, so the update must turn it on again, or the+schedule stays paused after the reload.### Step 5 — Trigger and confirmdiff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 99a7b9cae5da..136d53f8d150 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5741,7 +5741,7 @@}},"external-data-schemas-delete-data": {- "description": "Delete the synced table data from PostHog but keep the schema entry. The schema remains visible in the source and can be re-synced. Use this to clear stale or corrupt data before triggering a fresh sync.",+ "description": "Delete the synced table data from PostHog but keep the schema entry. This also sets should_sync to false and pauses the schedule, so the next scheduled run does not rebuild the table. To sync the table again, set should_sync to true with 'external-data-schemas-partial-update', then call 'external-data-schemas-reload'. To clear stale or corrupt data and keep syncing on, use 'external-data-schemas-resync' instead.","category": "Warehouse sources","feature": "warehouse_sources","summary": "Delete synced table data",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 7df0ed0ce6a9..a20cce51ece9 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5841,7 +5841,7 @@}},"external-data-schemas-delete-data": {- "description": "Delete the synced table data from PostHog but keep the schema entry. The schema remains visible in the source and can be re-synced. Use this to clear stale or corrupt data before triggering a fresh sync.",+ "description": "Delete the synced table data from PostHog but keep the schema entry. This also sets should_sync to false and pauses the schedule, so the next scheduled run does not rebuild the table. To sync the table again, set should_sync to true with 'external-data-schemas-partial-update', then call 'external-data-schemas-reload'. To clear stale or corrupt data and keep syncing on, use 'external-data-schemas-resync' instead.","category": "Warehouse sources","feature": "warehouse_sources","summary": "Delete synced table data",