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(insights): hide onboarding empty states for warehouse projects (#123521)

Marius Andraf50bcfc6dfe2
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index eec69718721d..4167065e0857 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -6,6 +6,10 @@ showTitle: true
This is an internal guide to setting up and working with the data warehouse for PostHog engineers. If you're a PostHog user, check out our [data warehouse docs](https://posthog.com/docs/data-warehouse) instead.
+Projects with a connected warehouse source or warehouse table use ordinary empty insight results, even before ingesting events. They do not show sample-data placeholders or the project-wide "This project has no events yet" notice. Both onboarding messages wait until the warehouse setup check confirms no sources or tables exist; an unavailable check does not imply an empty project.
+
+Onboarding only checks warehouse setup for non-demo projects without events. Source detection returns an existence flag without serializing schemas, and table detection omits columns. Navigation refreshes an empty result so returning after source creation opens the Sources list.
+
## Model namespace reservation
The shared PostHog catalog reserves `models.*` for authored data models. New warehouse tables, endpoint saved queries, and managed viewsets cannot claim that namespace. The bare name `models` is reserved for the namespace container; use a name such as `models.revenue` for a model. Names such as `models_v2` remain available. Saved queries with no origin are treated as authored models for compatibility.
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.test.tsx b/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
index e23477ef9753..c2b511642d80 100644
--- a/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
+++ b/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
@@ -1,10 +1,12 @@
-import { MOCK_DEFAULT_ORGANIZATION, MOCK_DEFAULT_USER, MOCK_TEAM_ID } from 'lib/api.mock'
+import { MOCK_DEFAULT_ORGANIZATION, MOCK_DEFAULT_TEAM, MOCK_DEFAULT_USER, MOCK_TEAM_ID } from 'lib/api.mock'
import { render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
+import { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'
import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
@@ -14,6 +16,7 @@ import { verifyEmailLogic } from 'scenes/authentication/verify-email/verifyEmail
import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
+import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
@@ -32,6 +35,25 @@ window.POSTHOG_APP_CONTEXT = {
} as unknown as AppContext
describe('projectNoticeLogic', () => {
+ describe('projects without events', () => {
+ it.each<ProductSetupStatus>(['loading', 'unknown', 'has-data', 'needs-setup'])(
+ 'only shows the no-events notice after warehouse setup is ruled out (%s)',
+ (status) => {
+ initKeaTests()
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ userLogic.actions.loadUserSuccess({ ...MOCK_DEFAULT_USER, is_email_verified: true })
+ const logic = projectNoticeLogic()
+ logic.mount()
+ productSetupStatusLogic({ productKey: ProductKey.DATA_WAREHOUSE }).actions.setDetectedStatus(status)
+
+ expect(logic.values.postHogNoticeVariant === 'real_project_with_no_events').toBe(
+ status === 'needs-setup'
+ )
+ logic.unmount()
+ }
+ )
+ })
+
describe('proxy records conditional loading', () => {
let getItemSpy: jest.SpyInstance
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.tsx b/frontend/src/layout/navigation/projectNoticeLogic.tsx
index d1db7149f73d..502f2cd05a06 100644
--- a/frontend/src/layout/navigation/projectNoticeLogic.tsx
+++ b/frontend/src/layout/navigation/projectNoticeLogic.tsx
@@ -6,6 +6,7 @@ import { IconGear, IconPlus } from '@posthog/icons'
import api, { ApiError } from 'lib/api'
import { getProductPushDisplay } from 'lib/components/NavPanelAdvertisement/navPanelProductPushDisplay'
+import { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'
import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonBannerProps } from 'lib/lemon-ui/LemonBanner/LemonBanner'
@@ -18,6 +19,7 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { liveEventsLogic } from 'scenes/activity/live/liveEventsLogic'
import { verifyEmailLogic } from 'scenes/authentication/verify-email/verifyEmailLogic'
import { billingLogic, BillingAlertConfig } from 'scenes/billing/billingLogic'
+import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'
import { membersLogic } from 'scenes/organization/membersLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
@@ -31,7 +33,7 @@ import { userLogic } from 'scenes/userLogic'
import { brandingForProduct } from 'scenes/welcome/productBranding'
import { ProductKey } from '~/queries/schema/schema-general'
-import { OnboardingStepKey, UserType } from '~/types'
+import { OnboardingStepKey, TeamPublicType, TeamType, UserType } from '~/types'
import { EventIngestionRestrictionDetails } from './EventIngestionRestrictionDetails'
import { OrganizationMemberNoticeMessage } from './OrganizationMemberNoticeMessage'
@@ -225,9 +227,14 @@ export interface projectNoticeLogicValues {
memberCount: number // membersLogic
currentOrganizationId: string // organizationLogic
hasReverseProxy: boolean | null // reverseProxyCheckerLogic
+ warehouseSetupStatus: ProductSetupStatus // sampleDataStateLogic
user: UserType | null // userLogic
noticeDismissedThisSession: boolean
postHogNoticeVariant: ProjectNoticeVariant | null
+ projectData: {
+ currentTeam: TeamPublicType | TeamType | null
+ warehouseSetupStatus: ProductSetupStatus
+ }
projectNotice: ProjectNoticeBlueprint | null
projectNoticeDismissKey: string | null
projectNoticeVariant: ProjectNoticeVariant | null
@@ -275,9 +282,19 @@ export interface projectNoticeLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface projectNoticeLogicMeta {
__keaTypeGenInternalSelectorTypes: {
+ projectData: (
+ currentTeam: TeamPublicType | TeamType | null,
+ warehouseSetupStatus: ProductSetupStatus
+ ) => {
+ currentTeam: TeamPublicType | TeamType | null
+ warehouseSetupStatus: ProductSetupStatus
+ }
postHogNoticeVariant: (
currentOrganization: null | import('~/types').OrganizationType,
- currentTeam: null | import('~/types').TeamPublicType | import('~/types').TeamType,
+ projectData: {
+ currentTeam: TeamPublicType | TeamType | null
+ warehouseSetupStatus: ProductSetupStatus
+ },
preflight: null | import('~/types').PreflightStatus,
isCloudOrDev: boolean | undefined,
user: UserType | null,
@@ -356,6 +373,8 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
// complete on the same signal. The checker throttles its own detection query internally.
reverseProxyCheckerLogic,
['hasReverseProxy'],
+ sampleDataStateLogic,
+ ['warehouseSetupStatus'],
],
actions: [
eventUsageLogic,
@@ -396,10 +415,20 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
noticeDismissedThisSession: [false, { dismissProjectNotice: () => true }],
}),
selectors({
+ projectData: [
+ (s) => [teamLogic.selectors.currentTeam, s.warehouseSetupStatus],
+ (
+ currentTeam: TeamPublicType | TeamType | null,
+ warehouseSetupStatus: ProductSetupStatus
+ ): { currentTeam: TeamPublicType | TeamType | null; warehouseSetupStatus: ProductSetupStatus } => ({
+ currentTeam,
+ warehouseSetupStatus,
+ }),
+ ],
postHogNoticeVariant: [
(s) => [
organizationLogic.selectors.currentOrganization,
- teamLogic.selectors.currentTeam,
+ s.projectData,
preflightLogic.selectors.preflight,
preflightLogic.selectors.isCloudOrDev,
userLogic.selectors.user,
@@ -418,7 +447,7 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
],
(
organization: null | import('~/types').OrganizationType,
- currentTeam: null | import('~/types').TeamPublicType | import('~/types').TeamType,
+ { currentTeam, warehouseSetupStatus }: projectNoticeLogicValues['projectData'],
preflight: null | import('~/types').PreflightStatus,
isCloudOrDev: boolean | undefined,
user: UserType | null,
@@ -475,6 +504,7 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
!isNoticeDismissed('real_project_with_no_events') &&
currentTeam &&
!currentTeam.ingested_event &&
+ warehouseSetupStatus === 'needs-setup' &&
// Belt-and-braces: never claim "no events" while the live activity feed is
// actively rendering events on the same screen — `currentTeam.ingested_event`
// can lag behind the live SSE stream during the first ingestion window.
diff --git a/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx b/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
index fdccc2a017bc..694249d0d00f 100644
--- a/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
+++ b/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
@@ -475,9 +475,8 @@ export const DataWarehouseNeedsSetup: ProductEmptyStateStory = productEmptyState
{
mocks: {
get: {
- // nosemgrep: no-environments-api-urls-frontend -- both APIs are env-scoped, so the msw mocks must match /api/environments to intercept them
- '/api/environments/:team_id/external_data_sources/': [200, { results: [] }],
- '/api/environments/:team_id/warehouse_tables/': [200, { results: [] }],
+ '/api/projects/:team_id/external_data_sources/exists/': [200, { exists: false }],
+ '/api/projects/:team_id/warehouse_tables/': [200, { results: [] }],
},
},
}
diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts
index 9f1ac8c70eb5..c5f5bebfbb71 100644
--- a/frontend/src/mocks/handlers.ts
+++ b/frontend/src/mocks/handlers.ts
@@ -112,6 +112,7 @@ export const defaultMocks: Mocks = {
'/api/projects/:team_id/dashboard_templates': EMPTY_PAGINATED_RESPONSE,
'/api/projects/:team_id/dashboard_templates/repository/': [],
'/api/environments/:team_id/external_data_sources/': EMPTY_PAGINATED_RESPONSE,
+ '/api/projects/:team_id/external_data_sources/exists/': { exists: false },
'/api/projects/:team_id/notebooks': () => {
// this was matching on `?contains=query` but that made MSW unhappy and seems unnecessary
return [
diff --git a/frontend/src/scenes/insights/EmptyStates/InsightEmptyState.test.tsx b/frontend/src/scenes/insights/EmptyStates/InsightEmptyState.test.tsx
index 2e28be0c58a8..a5010ca97fdf 100644
--- a/frontend/src/scenes/insights/EmptyStates/InsightEmptyState.test.tsx
+++ b/frontend/src/scenes/insights/EmptyStates/InsightEmptyState.test.tsx
@@ -2,7 +2,7 @@ import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
import '@testing-library/jest-dom'
-import { cleanup, render } from '@testing-library/react'
+import { cleanup, render, waitFor } from '@testing-library/react'
import { teamLogic } from 'scenes/teamLogic'
@@ -69,11 +69,13 @@ describe('EmptyStates', () => {
props: { sampleDataVariant: null },
expectSampleData: false,
},
- ])('renders $name', ({ team, props, expectSampleData }) => {
+ ])('renders $name', async ({ team, props, expectSampleData }) => {
mountWithTeam(team)
const { container } = render(<InsightEmptyState {...props} />)
- expect(!!container.querySelector('[data-attr="insight-sample-data-state"]')).toBe(expectSampleData)
+ await waitFor(() =>
+ expect(!!container.querySelector('[data-attr="insight-sample-data-state"]')).toBe(expectSampleData)
+ )
expect(!!container.querySelector('[data-attr="insight-empty-state"]')).toBe(!expectSampleData)
})
})
diff --git a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts
index 8083fd691509..c627a0de4147 100644
--- a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts
+++ b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts
@@ -1,12 +1,18 @@
import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { clearAllCachedHasData } from 'lib/components/ProductEmptyState/setupDetectionLogic'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
import { ExportType } from '~/exporter/types'
+import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { dataWarehouseSetupLogic } from 'products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic'
+
import { sampleDataStateLogic } from './sampleDataStateLogic'
describe('sampleDataStateLogic', () => {
@@ -19,7 +25,8 @@ describe('sampleDataStateLogic', () => {
// The global is read inside the selector, so it must be in place before the selector first
// computes (as on real shared pages, where Django injects it before React runs).
function mount(currentTeam: unknown): void {
- initKeaTests(false)
+ clearAllCachedHasData()
+ initKeaTests()
teamLogic.mount()
teamLogic.actions.loadCurrentTeamSuccess(currentTeam as any)
logic = sampleDataStateLogic()
@@ -28,12 +35,60 @@ describe('sampleDataStateLogic', () => {
it('shows the placeholder for a project that never ingested an event', async () => {
mount({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ expect(logic.values.shouldShowSampleData).toBe(false)
+ await expectLogic(dataWarehouseSetupLogic).toDispatchActions(['detectStatusSuccess'])
await expectLogic(logic).toMatchValues({ shouldShowSampleData: true })
})
- it('hides the placeholder once a project has ingested', async () => {
- mount({ ...MOCK_DEFAULT_TEAM, ingested_event: true })
- await expectLogic(logic).toMatchValues({ shouldShowSampleData: false })
+ it.each([
+ ['/api/projects/:team_id/external_data_sources/exists/', { exists: true }],
+ ['/api/projects/:team_id/warehouse_tables/', { results: [{ id: 'example-table' }] }],
+ ])('hides samples when %s exist without events', async (resource, response) => {
+ useMocks({
+ get: { [resource as string]: response },
+ })
+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ await expectLogic(dataWarehouseSetupLogic).toDispatchActions(['detectStatusSuccess'])
+ expect(logic.values.shouldShowSampleData).toBe(false)
+ })
+
+ it('does not claim the project is empty when warehouse detection fails', async () => {
+ useMocks({ get: { '/api/projects/:team_id/warehouse_tables/': () => [503, {}] } })
+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ await expectLogic(dataWarehouseSetupLogic).toDispatchActions(['detectStatusSuccess'])
+ expect(logic.values.shouldShowSampleData).toBe(false)
+ })
+
+ it.each([{ ingested_event: true }, { ingested_event: false, is_demo: true }])(
+ 'does not start warehouse detection for an ineligible project (%j)',
+ async (team) => {
+ mount({ ...MOCK_DEFAULT_TEAM, ...team })
+ await expectLogic(logic).toMatchValues({ shouldShowSampleData: false })
+ expect(dataWarehouseSetupLogic.isMounted()).toBe(false)
+ }
+ )
+
+ it('starts detection when the team loads and stops it after ingestion', async () => {
+ mount(null)
+ expect(dataWarehouseSetupLogic.isMounted()).toBe(false)
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ await expectLogic(dataWarehouseSetupLogic).toDispatchActions(['detectStatusSuccess'])
+ expect(logic.values.shouldShowSampleData).toBe(true)
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: true })
+ expect(dataWarehouseSetupLogic.isMounted()).toBe(false)
+ expect(logic.values.shouldShowSampleData).toBe(false)
+ })
+
+ it('refreshes warehouse setup on navigation while the detector stays mounted', async () => {
+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: false })
+ await expectLogic(dataWarehouseSetupLogic).toDispatchActions(['detectStatusSuccess'])
+ expect(logic.values.shouldShowSampleData).toBe(true)
+
+ useMocks({ get: { '/api/projects/:team_id/external_data_sources/exists/': { exists: true } } })
+ await expectLogic(dataWarehouseSetupLogic, () => router.actions.push(urls.sources()))
+ .toFinishAllListeners()
+ .toMatchValues({ setupStatus: 'has-data' })
+ expect(logic.values.shouldShowSampleData).toBe(false)
})
// Regression guard for the shared-dashboard placeholder bug: TeamPublicSerializer omits
@@ -43,5 +98,6 @@ describe('sampleDataStateLogic', () => {
window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }
mount({ ...MOCK_DEFAULT_TEAM, ingested_event: undefined })
await expectLogic(logic).toMatchValues({ shouldShowSampleData: false })
+ expect(dataWarehouseSetupLogic.isMounted()).toBe(false)
})
})
diff --git a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
index 15b3905eb11d..5f882dfc28db 100644
--- a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
+++ b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
@@ -1,50 +1,100 @@
-import { MakeLogicType, connect, kea, path, selectors } from 'kea'
+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, selectors } from 'kea'
+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
+import { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'
import { teamLogic } from 'scenes/teamLogic'
import { isSharedView } from '~/exporter/exporterViewLogic'
+import { ProductKey } from '~/queries/schema/schema-general'
+
+import { dataWarehouseSetupLogic } from 'products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic'
import type { TeamPublicType, TeamType } from '../../../types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sampleDataStateLogicValues {
+ warehouseSetupStatus: ProductSetupStatus // productSetupStatusLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
+ needsWarehouseDetection: boolean
shouldShowSampleData: boolean
}
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface sampleDataStateLogicActions {
+ syncWarehouseDetection: () => {
+ value: true
+ }
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sampleDataStateLogicMeta {
__keaTypeGenInternalSelectorTypes: {
- shouldShowSampleData: (currentTeam: TeamPublicType | TeamType | null) => boolean
+ needsWarehouseDetection: (currentTeam: TeamPublicType | TeamType | null) => boolean
+ shouldShowSampleData: (needsWarehouseDetection: boolean, warehouseSetupStatus: ProductSetupStatus) => boolean
}
}
export type sampleDataStateLogicType = MakeLogicType<
sampleDataStateLogicValues,
- {},
+ sampleDataStateLogicActions,
Record<string, any>,
sampleDataStateLogicMeta
>
/**
- * Gates the pre-ingestion sample-data placeholder: only projects that never ingested an event see
- * it. The wizard setup status shown on the placeholder comes from `setupWizardStatusLogic`.
+ * Gates the sample-data placeholder on confirmed absence of events and warehouse setup.
+ * The wizard setup status shown on the placeholder comes from `setupWizardStatusLogic`.
*/
export const sampleDataStateLogic = kea<sampleDataStateLogicType>([
path(['scenes', 'insights', 'EmptyStates', 'sampleDataStateLogic']),
connect(() => ({
- values: [teamLogic, ['currentTeam']],
+ values: [
+ teamLogic,
+ ['currentTeam'],
+ productSetupStatusLogic({ productKey: ProductKey.DATA_WAREHOUSE }),
+ ['status as warehouseSetupStatus'],
+ ],
})),
+ actions({ syncWarehouseDetection: true }),
selectors({
- shouldShowSampleData: [
+ needsWarehouseDetection: [
(s) => [s.currentTeam],
+ (currentTeam: TeamPublicType | TeamType | null): boolean =>
+ !isSharedView() && !!currentTeam && !currentTeam.ingested_event && !currentTeam.is_demo,
+ ],
+ shouldShowSampleData: [
+ (s) => [s.needsWarehouseDetection, s.warehouseSetupStatus],
// Never show the placeholder in shared/embedded/exported views: `TeamPublicSerializer`
// omits `ingested_event`, so it reads as `undefined` and would otherwise falsely flag
// every empty tile on a real, data-carrying project as "never ingested". External
// viewers should just see the normal "No data" state.
- (
- currentTeam: null | import('../../../types').TeamPublicType | import('../../../types').TeamType
- ): boolean => !isSharedView() && !!currentTeam && !currentTeam.ingested_event && !currentTeam.is_demo,
+ (needsWarehouseDetection: boolean, warehouseSetupStatus: ProductSetupStatus): boolean =>
+ needsWarehouseDetection && warehouseSetupStatus === 'needs-setup',
],
}),
+ listeners(({ actions, values, cache }) => ({
+ syncWarehouseDetection: () => {
+ if (values.needsWarehouseDetection) {
+ if (cache.warehouseDetectionTeamId !== values.currentTeam?.id) {
+ cache.disposables.add(
+ () => {
+ const unmount = dataWarehouseSetupLogic.mount()
+ cache.warehouseDetectionTeamId = values.currentTeam?.id
+ return () => {
+ unmount()
+ cache.warehouseDetectionTeamId = null
+ }
+ },
+ 'warehouseDetection',
+ { pauseOnPageHidden: false }
+ )
+ }
+ } else {
+ cache.disposables.dispose('warehouseDetection')
+ }
+ },
+ [teamLogic.actionTypes.loadCurrentTeamSuccess]: () => actions.syncWarehouseDetection(),
+ [teamLogic.actionTypes.updateCurrentTeamSuccess]: () => actions.syncWarehouseDetection(),
+ })),
+ afterMount(({ actions }) => actions.syncWarehouseDetection()),
])
diff --git a/posthog/test/repo_invariants/test_pagination_contract.py b/posthog/test/repo_invariants/test_pagination_contract.py
index 3cca89972906..f9fbbd21ef26 100644
--- a/posthog/test/repo_invariants/test_pagination_contract.py
+++ b/posthog/test/repo_invariants/test_pagination_contract.py
@@ -159,6 +159,8 @@ EXISTING_CUSTOM_LIST_VIEWSETS = {
"products.data_warehouse.backend.presentation.views.fix_hogql.FixHogQLViewSet",
"products.data_warehouse.backend.presentation.views.saved_query.viewset.DataWarehouseSavedQueryViewSet",
"products.data_warehouse.backend.presentation.views.saved_query_column_annotation.DataWarehouseSavedQueryColumnAnnotationViewSet",
+ # extend_schema_view wraps the inherited DRF list solely to document include_columns.
+ "products.data_warehouse.backend.presentation.views.table.TableViewSet",
"products.data_warehouse.backend.presentation.views.view_link.ViewLinkViewSet",
"products.endpoints.backend.presentation.views.api.EndpointViewSet",
"products.error_tracking.backend.presentation.views.alerts.ErrorTrackingAlertViewSet",
diff --git a/products/data_warehouse/backend/presentation/views/table.py b/products/data_warehouse/backend/presentation/views/table.py
index e3ec336f0e14..f8ec43401630 100644
--- a/products/data_warehouse/backend/presentation/views/table.py
+++ b/products/data_warehouse/backend/presentation/views/table.py
@@ -7,7 +7,13 @@ from django.db.models import QuerySet
import boto3
import posthoganalytics
-from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_field
+from drf_spectacular.utils import (
+ OpenApiParameter,
+ OpenApiResponse,
+ extend_schema,
+ extend_schema_field,
+ extend_schema_view,
+)
from rest_framework import filters, parsers, request, response, serializers, status, viewsets
from posthog.schema import DatabaseSerializedFieldType
@@ -581,6 +587,18 @@ class CreateTableFromUploadSerializer(UploadedFileSerializer):
return table_name
+@extend_schema_view(
+ list=extend_schema(
+ parameters=[
+ OpenApiParameter(
+ "include_columns",
+ bool,
+ description="Include table columns. Disable for lightweight table existence or name lookups.",
+ default=True,
+ )
+ ]
+ )
+)
class TableViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.ModelViewSet):
"""
Create, Read, Update and Delete Warehouse Tables.
diff --git a/products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic.ts b/products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic.ts
index ec5cf3ee4606..39d6c4d27e40 100644
--- a/products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic.ts
+++ b/products/data_warehouse/frontend/emptyState/dataWarehouseSetupLogic.ts
@@ -1,8 +1,14 @@
-import api from 'lib/api'
+import { router } from 'kea-router'
+
import { createSetupDetectionLogic } from 'lib/components/ProductEmptyState/setupDetectionLogic'
+import { teamLogic } from 'scenes/teamLogic'
import { ProductKey } from '~/queries/schema/schema-general'
+import { externalDataSourcesExistsRetrieve } from 'products/warehouse_sources/frontend/generated/api'
+
+import { warehouseTablesList } from '../generated/api'
+
/**
* Setup detection for the data warehouse empty state. A managed source counts
* from the moment it's created (its row with sync status is the useful scene),
@@ -13,11 +19,12 @@ export const dataWarehouseSetupLogic = createSetupDetectionLogic({
path: ['products', 'data_warehouse', 'frontend', 'emptyState', 'dataWarehouseSetupLogic'],
cacheHasData: true,
revalidateCachedHasData: true,
+ recheckActionTypes: () => [router.actionTypes.locationChanged],
detect: async () => {
const [sources, tables] = await Promise.all([
- api.externalDataSources.list(),
- api.dataWarehouseTables.list({ limit: 1 }),
+ externalDataSourcesExistsRetrieve(String(teamLogic.values.currentTeamId)),
+ warehouseTablesList(String(teamLogic.values.currentTeamId), { limit: 1, include_columns: false }),
])
- return sources.results.length > 0 || tables.results.length > 0 ? 'has-data' : 'needs-setup'
+ return sources.exists || tables.results.length > 0 ? 'has-data' : 'needs-setup'
},
})
diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.ts
index d64d089114e6..d85459139094 100644
--- a/products/data_warehouse/frontend/generated/api.schemas.ts
+++ b/products/data_warehouse/frontend/generated/api.schemas.ts
@@ -6017,6 +6017,10 @@ export type WarehouseSavedQueryDraftsListParams = {
}
export type WarehouseTablesListParams = {
+ /**
+ * Include table columns. Disable for lightweight table existence or name lookups.
+ */
+ include_columns?: boolean
/**
* Number of results to return per page.
*/
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_source/viewset.py b/products/warehouse_sources/backend/presentation/views/external_data_source/viewset.py
index ff2785da5072..58b5f52a33d7 100644
--- a/products/warehouse_sources/backend/presentation/views/external_data_source/viewset.py
+++ b/products/warehouse_sources/backend/presentation/views/external_data_source/viewset.py
@@ -9,6 +9,7 @@ from django.db.models import Prefetch
from drf_spectacular.utils import extend_schema
from opentelemetry import trace
from rest_framework import filters, serializers, viewsets
+from rest_framework.decorators import action
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
@@ -18,7 +19,7 @@ from posthog.hogql.database.database import Database
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.models.user import User
-from posthog.permissions import AccessControlPermission, APIScopePermission, TeamMemberAccessPermission
+from posthog.permissions import AccessControlPermission, APIScopePermission, TeamMemberAccessPermission, is_service_auth
from posthog.rate_limit import (
CustomSourceAIBuilderBurstThrottle,
CustomSourceAIBuilderDailyThrottle,
@@ -43,6 +44,10 @@ from .source_setup import ExternalDataSourceSetupMixin
from .webhook_setup import ExternalDataSourceWebhookSetupMixin
+class ExternalDataSourceExistsSerializer(serializers.Serializer):
+ exists = serializers.BooleanField(help_text="Whether the project has any accessible external data sources.")
+
+
@extend_schema(extensions={"x-product": "warehouse_sources"})
class ExternalDataSourceViewSet(
ExternalDataSourceSetupMixin,
@@ -99,6 +104,7 @@ class ExternalDataSourceViewSet(
"draft_custom_manifest",
]
scope_object_read_actions = [
+ "exists",
"list",
"retrieve",
"jobs",
@@ -118,6 +124,14 @@ class ExternalDataSourceViewSet(
search_fields = ["source_type", "prefix"]
ordering = "-created_at"
+ @extend_schema(responses=ExternalDataSourceExistsSerializer)
+ @action(methods=["GET"], detail=False, pagination_class=None, filter_backends=[])
+ def exists(self, request: Request, **kwargs: object) -> Response:
+ queryset = self.filter_queryset(self.get_queryset())
+ if not is_service_auth(request):
+ queryset = self.user_access_control.filter_queryset_by_access_level(queryset)
+ return Response(ExternalDataSourceExistsSerializer({"exists": queryset.exists()}).data)
+
def check_object_permissions(self, request: Request, obj: Any) -> None:
super().check_object_permissions(request, obj)
if request.method not in ("GET", "HEAD", "OPTIONS") and isinstance(obj, ExternalDataSource):
diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.py
index bedf2ff5c9e2..fe2a1502e69a 100644
--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py
+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py
@@ -226,6 +226,29 @@ class TestExternalDataSource(APIBaseTest):
should_sync=should_sync,
)
+ def test_exists_ignores_deleted_and_other_project_sources_without_loading_schemas(self) -> None:
+ source = self._make_source("exists")
+ self._make_schema_with_table(source, "example_customers")
+ url = f"/api/projects/{self.team.pk}/external_data_sources/exists/"
+
+ with (
+ patch(
+ "products.warehouse_sources.backend.presentation.views.external_data_source.viewset.Database.create_for"
+ ) as database,
+ CaptureQueriesContext(connection) as queries,
+ ):
+ response = self.client.get(url)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(response.json(), {"exists": True})
+ database.assert_not_called()
+ self.assertFalse(any(ExternalDataSchema._meta.db_table in query["sql"] for query in queries))
+
+ source.deleted = True
+ source.save(update_fields=["deleted"])
+ other_team = Team.objects.create(organization=self.organization)
+ ExternalDataSource.objects.create(team=other_team, source_type="Stripe")
+ self.assertEqual(self.client.get(url).json(), {"exists": False})
+
def test_list_serializes_trimmed_schema_shape_while_retrieve_stays_full(self):
# The sources list embeds every schema of every source, so it serializes a trimmed per-schema
# shape (the fields the list UI reads); the single-source view keeps the full schema.
diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source_access_control.py b/products/warehouse_sources/backend/tests/api/test_external_data_source_access_control.py
index 2f21fa1d8c42..9ad7c277e95b 100644
--- a/products/warehouse_sources/backend/tests/api/test_external_data_source_access_control.py
+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source_access_control.py
@@ -147,6 +147,17 @@ class TestExternalDataSourceAccessControl(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_200_OK)
+ @parameterized.expand([("viewer", True), ("none", False)])
+ def test_exists_respects_source_access(self, access_level: str, expected: bool) -> None:
+ self._create_access_control(self.viewer_user, access_level="viewer")
+ self._create_access_control(self.viewer_user, resource_id=str(self.source.id), access_level=access_level)
+ self.client.force_login(self.viewer_user)
+
+ response = self.client.get(f"/api/projects/{self.team.pk}/external_data_sources/exists/")
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(response.json(), {"exists": expected})
+
def test_viewer_can_retrieve_source(self):
self._create_access_control(self.viewer_user, access_level="viewer")
diff --git a/products/warehouse_sources/frontend/generated/api.schemas.ts b/products/warehouse_sources/frontend/generated/api.schemas.ts
index 58d11bd9e74c..3cd39f1189ec 100644
--- a/products/warehouse_sources/frontend/generated/api.schemas.ts
+++ b/products/warehouse_sources/frontend/generated/api.schemas.ts
@@ -10053,6 +10053,11 @@ export interface DraftCustomManifestResponseApi {
error: string | null
}
+export interface ExternalDataSourceExistsApi {
+ /** Whether the project has any accessible external data sources. */
+ exists: boolean
+}
+
/**
* Source config as flat keys. For source_type 'Custom': 'manifest_json' (a stringified RESTAPIConfig describing client.base_url, auth, and resources) plus the credential for the manifest's declared auth type — 'auth_token' (bearer), 'auth_api_key' (api_key), or 'auth_password' (http_basic). Secrets stay in these auth_* keys, never inline in the manifest.
*/
diff --git a/products/warehouse_sources/frontend/generated/api.ts b/products/warehouse_sources/frontend/generated/api.ts
index d497013e0086..c3e95ef5ecca 100644
--- a/products/warehouse_sources/frontend/generated/api.ts
+++ b/products/warehouse_sources/frontend/generated/api.ts
@@ -33,6 +33,7 @@ import type {
ExternalDataSourceConnectionOptionApi,
ExternalDataSourceCreateApi,
ExternalDataSourceCreateResponseApi,
+ ExternalDataSourceExistsApi,
ExternalDataSourceSerializersApi,
ExternalDataSourcesConnectLinkRetrieveParams,
ExternalDataSourcesJobsListParams,
@@ -1260,6 +1261,23 @@ export const externalDataSourcesDraftCustomManifestCreate = async (
})
}
+export const getExternalDataSourcesExistsRetrieveUrl = (projectId: string) => {
+ return `/api/projects/${projectId}/external_data_sources/exists/`
+}
+
+/**
+ * Create, Read, Update and Delete External data Sources.
+ */
+export const externalDataSourcesExistsRetrieve = async (
+ projectId: string,
+ options?: RequestInit
+): Promise<ExternalDataSourceExistsApi> => {
+ return apiMutator<ExternalDataSourceExistsApi>(getExternalDataSourcesExistsRetrieveUrl(projectId), {
+ ...options,
+ method: 'GET',
+ })
+}
+
export const getExternalDataSourcesOauthAccountsRetrieveUrl = (
projectId: string,
params: ExternalDataSourcesOauthAccountsRetrieveParams
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 8bdd4e8b03c9..0895143777f1 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -54119,6 +54119,11 @@ export namespace Schemas {
latest_error: string | null;
}
+ export interface ExternalDataSourceExists {
+ /** Whether the project has any accessible external data sources. */
+ exists: boolean;
+ }
+
export interface ExternalDataSourceRevenueAnalyticsConfig {
enabled?: boolean;
include_invoiceless_charges?: boolean;
@@ -140979,6 +140984,10 @@ export namespace Schemas {
} as const;
export type WarehouseTablesListParams = {
+ /**
+ * Include table columns. Disable for lightweight table existence or name lookups.
+ */
+ include_columns?: boolean;
/**
* Number of results to return per page.
*/