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): say up front when a new source needs a table prefix (#114626)

Tom Owersb9868508cd36
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
index ae98fc007d83..511b2dc21aed 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
@@ -569,7 +569,7 @@ function DatabaseFirewallHint(): JSX.Element | null {
}
function SecondStep({ sourceWizardLogicProps }: { sourceWizardLogicProps?: SourceWizardLogicProps }): JSX.Element {
- const { selectedConnector, source, sourceConnectionDetails } = useValues(sourceWizardLogic)
+ const { selectedConnector, source, sourceConnectionDetails, prefixRequired } = useValues(sourceWizardLogic)
const selectedAccessMethod = getEffectiveAccessMethod(
2,
sourceConnectionDetails?.access_method,
@@ -618,6 +618,7 @@ function SecondStep({ sourceWizardLogicProps }: { sourceWizardLogicProps?: Sourc
sourceConfig={selectedConnector}
initialAccessMethod={sourceConnectionDetails?.access_method ?? source.access_method}
showAccessMethodSelector={false}
+ prefixRequired={prefixRequired}
sourceWizardLogicProps={sourceWizardLogicProps}
/>
</div>
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index aef3f4abfb9f..e22e4715ed2f 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -300,6 +300,15 @@ export class UnusableUploadedFileError extends Error {
export const WRONG_UPLOADED_FILE_MESSAGE =
'This JSON file is missing the fields PostHog needs. Upload the key file exactly as it was generated, without editing its contents.'
+// Mirrors the backend `prefix_required` check: a second unprefixed source of the same type would
+// write to the same table names, so the API rejects it.
+export function isPrefixRequired(sources: ExternalDataSource[] | undefined, sourceType: string | undefined): boolean {
+ if (!sourceType || !sources) {
+ return false
+ }
+ return sources.some((source) => source.source_type === sourceType && !source.prefix)
+}
+
export function resolveConnectErrorMessage(e: any): string {
const detail = e?.detail === GENERIC_SERVER_ERROR_DETAIL ? undefined : e?.detail
const apiMessage = e?.data?.message ?? detail
@@ -476,6 +485,7 @@ export interface sourceWizardLogicValues {
| 'Tables ready to query'
nextButtonDisabledReason: string | null
nextButtonText: string
+ prefixRequired: boolean
requiredTables: any
returnConfig: {
returnLabel: string
@@ -948,6 +958,10 @@ export interface sourceWizardLogicMeta {
selectedConnector: SourceConfigResponseApi | null,
isManualLinkFormVisible: boolean
) => boolean | SourceConfigResponseApi
+ prefixRequired: (
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,
+ selectedConnector: SourceConfigResponseApi | null
+ ) => boolean
connectors: (
dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,
availableSources: any
@@ -1737,6 +1751,13 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
(selectedConnector: SourceConfigResponseApi | null, isManualLinkFormVisible: boolean) =>
selectedConnector || isManualLinkFormVisible,
],
+ prefixRequired: [
+ (s) => [s.dataWarehouseSources, s.selectedConnector],
+ (
+ sources: PaginatedResponse<ExternalDataSource> | null,
+ selectedConnector: SourceConfigResponseApi | null
+ ): boolean => isPrefixRequired(sources?.results, selectedConnector?.name),
+ ],
connectors: [
(s) => [s.dataWarehouseSources, s.availableSources],
(
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
index d21b973b552d..cc77a3abe8f3 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
@@ -10,7 +10,7 @@ import { captureMarketingCrossSellClick, getMarketingCrossSellAttribution } from
import { ProductIntentContext, ProductKey, WebStatsBreakdown } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import type { AvailableColumn, ExternalDataSourceSyncSchema, IncrementalField } from '~/types'
+import type { AvailableColumn, ExternalDataSource, ExternalDataSourceSyncSchema, IncrementalField } from '~/types'
import type { SourceConfigResponseApi } from 'products/warehouse_sources/frontend/generated/api.schemas'
@@ -18,6 +18,7 @@ import {
buildKeaFormDefaultFromSourceDetails,
getDatabaseSchemaPayload,
getErrorsForFields,
+ isPrefixRequired,
mergeRestoredSourceFormValues,
resolveConnectErrorMessage,
shouldHydrateSourceFromUrl,
@@ -273,6 +274,21 @@ describe('sourceWizardLogic', () => {
expect(shouldHydrateSourceFromUrl(2, postgresSource, postgresSource, 'warehouse', 'direct')).toBe(true)
})
+ describe('isPrefixRequired', () => {
+ const source = (source_type: string, prefix: string | null): ExternalDataSource =>
+ ({ source_type, prefix }) as ExternalDataSource
+
+ test.each([
+ ['no sources yet', [], false],
+ ['an unprefixed source of the same type', [source('Stripe', null)], true],
+ ['an empty-string prefix on the same type', [source('Stripe', '')], true],
+ ['only prefixed sources of the same type', [source('Stripe', 'eu')], false],
+ ['an unprefixed source of another type', [source('Hubspot', null)], false],
+ ])('with %s', (_, sources, expected) => {
+ expect(isPrefixRequired(sources, 'Stripe')).toBe(expected)
+ })
+ })
+
describe('resolveConnectErrorMessage', () => {
it('guides toward ad blockers when a request never reaches the server', () => {
// A thrown fetch has no HTTP status; without this branch the user only sees "Failed to fetch".
diff --git a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx
index e635beaa957c..12d68643ecf1 100644
--- a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx
@@ -51,6 +51,8 @@ const NO_OP_SET_VALUE = (): void => undefined
export interface SourceFormProps {
sourceConfig: SourceConfigResponseApi
showPrefix?: boolean
+ /** Another source of this type already has no prefix, so the API rejects a new one without a prefix. */
+ prefixRequired?: boolean
showDescription?: boolean
showAccessMethodSelector?: boolean
showDirectQueryToggle?: boolean
@@ -824,6 +826,7 @@ export default function SourceFormContainer(props: SourceFormProps): JSX.Element
export function SourceFormComponent({
sourceConfig,
showPrefix = true,
+ prefixRequired = false,
showDescription,
showAccessMethodSelector = true,
showDirectQueryToggle = false,
@@ -1033,8 +1036,12 @@ export function SourceFormComponent({
{showPrefix && !isDirectQuerySource && !customAiIntroActive && (
<LemonField
name="prefix"
- label="Table name prefix (optional)"
- help="Renames the tables PostHog creates. It doesn't filter which tables get imported. Use only letters, numbers, and underscores, and start with a letter or underscore."
+ label={prefixRequired ? 'Table name prefix' : 'Table name prefix (optional)'}
+ help={
+ prefixRequired
+ ? `You already have a ${sourceConfig.label ?? sourceConfig.name} source without a prefix. Add one so this connection's tables don't clash with it.`
+ : "Renames the tables PostHog creates. It doesn't filter which tables get imported. Use only letters, numbers, and underscores, and start with a letter or underscore."
+ }
>
{({ value, onChange }) => {
const cleaned = value ? value.trim().replace(/^_+|_+$/g, '') : ''