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): surface real errors and zero-table diagnostics from refresh schemas (#59014)

Tom Owersfcdc04c7a7e7
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index 6330584eece9..da738a7e8742 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -5471,7 +5471,11 @@ const api = {
}> {
return await new ApiRequest().externalDataSource(sourceId).withAction('delete_webhook').create()
},
- async refreshSchemas(sourceId: ExternalDataSource['id']): Promise<{ added: number; deleted: number }> {
+ async refreshSchemas(sourceId: ExternalDataSource['id']): Promise<{
+ added: number
+ deleted: number
+ total_tables_seen: number
+ }> {
return await new ApiRequest().externalDataSource(sourceId).withAction('refresh_schemas').create()
},
async bulkUpdateSchemas(
diff --git a/products/data_warehouse/backend/api/external_data_source.py b/products/data_warehouse/backend/api/external_data_source.py
index 78417bf44ae2..92c07a972e5f 100644
--- a/products/data_warehouse/backend/api/external_data_source.py
+++ b/products/data_warehouse/backend/api/external_data_source.py
@@ -1514,7 +1514,14 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
@action(methods=["POST"], detail=True)
@extend_schema(
responses={
- 200: {"type": "object", "properties": {"added": {"type": "integer"}, "deleted": {"type": "integer"}}}
+ 200: {
+ "type": "object",
+ "properties": {
+ "added": {"type": "integer"},
+ "deleted": {"type": "integer"},
+ "total_tables_seen": {"type": "integer"},
+ },
+ }
}
)
def refresh_schemas(self, request: Request, *args: Any, **kwargs: Any) -> Response:
@@ -1582,6 +1589,7 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
status=status.HTTP_400_BAD_REQUEST,
data={"message": error_message},
)
+
descriptions = {s.name: s.description for s in schemas}
with transaction.atomic():
ExternalDataSource._base_manager.filter(pk=instance.pk).select_for_update().get()
@@ -1624,10 +1632,15 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
team_id=self.team_id,
added=len(schemas_created),
deleted=len(schemas_deleted),
+ total_tables_seen=len(schemas),
)
return Response(
status=status.HTTP_200_OK,
- data={"added": len(schemas_created), "deleted": len(schemas_deleted)},
+ data={
+ "added": len(schemas_created),
+ "deleted": len(schemas_deleted),
+ "total_tables_seen": len(schemas),
+ },
)
@extend_schema(request=DatabaseSchemaRequestSerializer)
diff --git a/products/data_warehouse/backend/api/test/test_external_data_source.py b/products/data_warehouse/backend/api/test/test_external_data_source.py
index 01ab21b8e786..515ecf4de5ba 100644
--- a/products/data_warehouse/backend/api/test/test_external_data_source.py
+++ b/products/data_warehouse/backend/api/test/test_external_data_source.py
@@ -1273,7 +1273,7 @@ class TestExternalDataSource(APIBaseTest):
@patch("products.data_warehouse.backend.api.external_data_source.SourceRegistry.get_source")
def test_refresh_schemas_creates_new_schemas_and_returns_counts(self, mock_get_source):
- parsed_config = Mock()
+ parsed_config = Mock(spec=["to_dict"])
parsed_config.to_dict.return_value = {
"host": "localhost",
"port": "5432",
@@ -1297,6 +1297,7 @@ class TestExternalDataSource(APIBaseTest):
data = response.json()
self.assertEqual(data["added"], 2)
self.assertEqual(data["deleted"], 0)
+ self.assertEqual(data["total_tables_seen"], 2)
self.assertEqual(
ExternalDataSchema.objects.filter(team_id=self.team.pk, source_id=source.pk, deleted=False).count(), 2
)
@@ -1533,6 +1534,22 @@ class TestExternalDataSource(APIBaseTest):
self.assertEqual(response.status_code, 400)
self.assertIn("Could not fetch schemas from source", response.json().get("message", ""))
+ @patch("products.data_warehouse.backend.api.external_data_source.SourceRegistry.get_source")
+ def test_refresh_schemas_returns_zero_total_tables_seen_when_source_returns_nothing(self, mock_get_source):
+ mock_get_source.return_value.parse_config.return_value = None
+ mock_get_source.return_value.get_schemas.return_value = []
+ source = self._create_external_data_source()
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/external_data_sources/{source.pk}/refresh_schemas/"
+ )
+
+ self.assertEqual(response.status_code, 200)
+ data = response.json()
+ self.assertEqual(data["added"], 0)
+ self.assertEqual(data["deleted"], 0)
+ self.assertEqual(data["total_tables_seen"], 0)
+
@patch("products.data_warehouse.backend.api.external_data_source.capture_exception")
@patch("products.data_warehouse.backend.api.external_data_source.SourceRegistry.get_source")
def test_refresh_schemas_returns_specific_message_without_capture_for_expected_source_error(
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
index 18447a6eff71..4504e1bc4db1 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
@@ -636,22 +636,40 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([
},
refreshSchemas: async () => {
try {
- const { added = 0, deleted = 0 } = await api.externalDataSources.refreshSchemas(values.sourceId)
+ const {
+ added = 0,
+ deleted = 0,
+ total_tables_seen = 0,
+ } = await api.externalDataSources.refreshSchemas(values.sourceId)
actions.loadSource()
posthog.capture('schemas refreshed', {
sourceType: values.source?.source_type,
added,
deleted,
+ total_tables_seen,
})
- const parts = ['Schemas refreshed']
- if (added > 0 || deleted > 0) {
- parts.push(
- [added > 0 ? `${added} added` : null, deleted > 0 ? `${deleted} deleted` : null]
- .filter(Boolean)
- .join(' / ')
+ // Connected and got an empty table list — almost always a permissions
+ // or configuration issue on the source. Warn rather than silently succeed.
+ // If we also just removed previously-tracked schemas, call that out
+ // explicitly so the user knows their tracking list changed.
+ if (total_tables_seen === 0) {
+ const deletedSuffix =
+ deleted > 0
+ ? ` ${deleted} previously tracked table(s) were removed from the tracking list.`
+ : ''
+ lemonToast.warning(
+ `No tables found. Check the source credentials, permissions, and configuration.${deletedSuffix}`
)
+ return
+ }
+ if (added === 0 && deleted === 0) {
+ lemonToast.success(`No schema changes — all ${total_tables_seen} table(s) already tracked.`)
+ return
}
- lemonToast.success(parts.join(', '))
+ const counts = [added > 0 ? `${added} added` : null, deleted > 0 ? `${deleted} deleted` : null]
+ .filter(Boolean)
+ .join(' / ')
+ lemonToast.success(`Schemas refreshed: ${counts}`)
} catch (e: any) {
if (e.message) {
lemonToast.error(e.message)