: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): say what to do when some tables can't be read (#128834)
Tom Owers743a98801333
diff --git a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.test.ts b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.test.tsindex 4561dbdc796f..6950bc81c568 100644--- a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.test.ts+++ b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.test.ts@@ -1,6 +1,6 @@import type { ExternalDataSourceSyncSchema } from '~/types'-import { getDirectQuerySelectionDescription, getSyncFieldPlaceholder } from './SchemaForm'+import { getDirectQuerySelectionDescription, getSyncFieldPlaceholder, getUnreadableTablesNotice } from './SchemaForm'import { getDefaultExpandedSchemaKeys, groupTablesBySchema, splitQualifiedTableName } from './schemaGroupingUtils'const makeSchema = (table: string): ExternalDataSourceSyncSchema => ({@@ -43,6 +43,31 @@ describe('SchemaForm', () => {expect(getSyncFieldPlaceholder(syncType)).toEqual(expected)})+ it.each([+ ['every table is readable', [null, null], null],+ [+ 'one table is unreadable',+ ['Missing rak_promotion_code_read', null, null],+ "Your credentials can't read 1\u00a0table. Import the other tables now, then turn these on from the source's Schemas tab after you grant access.",+ ],+ [+ 'several tables are unreadable',+ ['Missing rak_promotion_code_read', 'Missing rak_invoice_item_read', null],+ "Your credentials can't read 2\u00a0tables. Import the other tables now, then turn these on from the source's Schemas tab after you grant access.",+ ],+ [+ 'every table is unreadable',+ ['Missing rak_charge_read', 'Missing rak_customer_read'],+ "Your credentials can't read any of these tables. Grant read access in your source provider, then go back a step and try again.",+ ],+ ] as const)('shows the unreadable tables notice when %s', (_, permissionErrors, expected) => {+ const schemas = permissionErrors.map((permission_error, index) => ({+ ...makeSchema(`table_${index}`),+ permission_error,+ }))+ expect(getUnreadableTablesNotice(schemas)).toEqual(expected)+ })+it('splits fully qualified table names into schema and table labels', () => {expect(splitQualifiedTableName('public.events')).toEqual({schemaName: 'public',diff --git a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsxindex aaa5962344fd..05ce61b5df0f 100644--- a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'import { IconInfo, IconWarning } from '@posthog/icons'import {+ LemonBanner,LemonButton,LemonCheckbox,LemonCollapse,@@ -46,6 +47,23 @@ export function getSyncFieldPlaceholder(syncType: ExternalDataSourceSyncSchema['return 'No sync field selected'}+// Tables the credentials can't read are left off. Without this note, users restart the whole+// wizard hoping the "Permission missing" tags clear, when they can import the rest and enable+// those tables later from the Schemas tab, which does not re-check permissions.+export function getUnreadableTablesNotice(schemas: ExternalDataSourceSyncSchema[]): string | null {+ const unreadableCount = schemas.filter((schema) => !!schema.permission_error).length++ if (unreadableCount === 0) {+ return null+ }++ if (unreadableCount === schemas.length) {+ return "Your credentials can't read any of these tables. Grant read access in your source provider, then go back a step and try again."+ }++ return `Your credentials can't read ${pluralize(unreadableCount, 'table', 'tables')}. Import the other tables now, then turn these on from the source's Schemas tab after you grant access.`+}+function getSchemaSelectionState(tables: ExternalDataSourceSyncSchema[]): boolean | 'indeterminate' {const enabledCount = tables.filter((table) => table.should_sync).length@@ -106,6 +124,7 @@ export default function SchemaForm(): JSX.Element {}, [containerRef])const showRows = databaseSchema.some((schema) => schema.rows != null)+ const unreadableTablesNotice = getUnreadableTablesNotice(databaseSchema)const hasManySchemas = databaseSchema.length > 10// Shown when the schema fetch returned zero tables. That can be transient — some sources@@ -389,6 +408,7 @@ export default function SchemaForm(): JSX.Element {You can enable more tables or change sync settings later on the source's Schemas tab.</p>)}+ {unreadableTablesNotice && <LemonBanner type="warning">{unreadableTablesNotice}</LemonBanner>}{hasManySchemas && (<div className="flex items-center gap-2"><LemonInput