: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(customer-analytics): block warehouse property saves with no mapping (#92624)
Tom Owers2eb50c4dafa8
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsxindex b7c9debae02f..31fd31b44555 100644--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx@@ -36,6 +36,7 @@ import {CustomPropertySourceMode,CustomPropertyTargetType,customPropertyDefinitionsLogic,+ keyColumnLabel,} from './customPropertyDefinitionsLogic'import {DISPLAY_TYPE_OPTIONS,@@ -204,7 +205,7 @@ function PersonSourceEditor(): JSX.Element {</span>),}))- const keyColumnLabel = isGroup ? 'group key column' : 'distinct ID column'+ const keyColumnLabelText = keyColumnLabel(customPropertyForm.targetType)// Bulk mapping needs the key column chosen first, since that is what it excludes. Naming the// reason in the disabled state keeps a wide table from being mapped with its identifier in it.const mapAllDisabledReason = !customPropertyForm.warehouseSource@@ -212,7 +213,7 @@ function PersonSourceEditor(): JSX.Element {: selectedTableColumnsLoading? 'Loading columns': !customPropertyForm.keyColumn?.trim()- ? `Choose the ${keyColumnLabel} first`+ ? `Choose the ${keyColumnLabelText} first`: !mappableColumns.length? 'Every column is mapped already': undefined@@ -408,8 +409,8 @@ function PersonSourceEditor(): JSX.Element {{warningCount > 0 && (<span className="text-warning text-xs">{warningCount === 1- ? '1 mapped property needs a look before you save.'- : `${warningCount} mapped properties need a look before you save.`}+ ? '1 mapping needs a look before you save.'+ : `${warningCount} mappings need a look before you save.`}</span>)}<div className="flex items-center gap-2">@@ -427,9 +428,9 @@ function PersonSourceEditor(): JSX.Element {</LemonButton></div><span className="text-secondary text-xs">- Mapping every column keeps the warehouse column names. The {keyColumnLabel} is left out, because- its values identify the {entityLabel} rather than describing it. Nothing is saved until you- create the property, so you can edit or remove any row first.+ Mapping every column keeps the warehouse column names. The {keyColumnLabelText} is left out,+ because its values identify the {entityLabel} rather than describing it. Nothing is saved until+ you create the property, so you can edit or remove any row first.</span></div>)}@@ -533,6 +534,7 @@ export function CustomPropertyModal(): JSX.Element {editingReferences,newWorkflowUrlLoading,targetTypeLocked,+ profileMappingDisabledReason,} = useValues(customPropertyDefinitionsLogic)const {closeModal,@@ -565,13 +567,6 @@ export function CustomPropertyModal(): JSX.Element {: option)- // A new person/group source needs at least one complete column → property pair. The mapping rows- // aren't LemonFields, so this gates the submit button rather than showing a per-field error.- const missingPersonMapping =- isProfileTarget &&- !hasExistingSource &&- !customPropertyForm.columnMappings.some((mapping) => mapping.column.trim() && mapping.property.trim())-const submitDisabledReason =// The select-options gate is account-only — the Type field is hidden for person, where a// leftover 'select' from switching targets would otherwise wedge the submit button.@@ -579,13 +574,12 @@ export function CustomPropertyModal(): JSX.Element {customPropertyForm.displayType === 'select' &&customPropertyForm.options.length === 0? 'Add at least one option'- : missingPersonMapping- ? 'Map at least one column to a property'- : targetType === 'account' && sourceMode === 'data_warehouse' && noViews- ? 'No materialized views are available'- : targetType === 'account' && sourceMode === 'workflow' && editingReferences.length === 0- ? 'Create a workflow that updates this property first'- : undefined+ : (profileMappingDisabledReason ??+ (targetType === 'account' && sourceMode === 'data_warehouse' && noViews+ ? 'No materialized views are available'+ : targetType === 'account' && sourceMode === 'workflow' && editingReferences.length === 0+ ? 'Create a workflow that updates this property first'+ : undefined))return (<LemonModaldiff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.tsindex dfd9d027f233..0838ae12d1e3 100644--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts@@ -393,6 +393,40 @@ describe('customPropertyDefinitionsLogic', () => {expect(logic.values.serializedColumnDescriptions).toEqual({ plan: 'The plan tier' })})+ it.each([+ ['nothing is mapped', [{ column: '', property: '', description: '' }], 'Map at least one column to a property'],+ [+ 'every complete row is the key column',+ [{ column: 'org_id', property: 'org_id', description: '' }],+ 'Map a column other than the distinct ID column',+ ],+ [+ 'a column other than the key column is mapped',+ [{ column: 'mrr', property: 'mrr', description: '' }],+ undefined,+ ],+ ] as [string, Record<string, string>[], string | undefined][])(+ 'gates creating a person source when %s',+ async (_, columnMappings, expectedReason) => {+ // The submit button reads this. A row on the key column is dropped from+ // column_property_map, so rows alone can look complete while the request carries an+ // empty map, which the backend rejects once the definition is already created.+ useMocks(defaultMocks())+ mountLogic()+ await expectLogic(logic, () => logic.actions.openCreateModal()).toDispatchActions([+ 'loadWarehouseTablesSuccess',+ ])+ logic.actions.setCustomPropertyFormValues({+ targetType: 'person',+ warehouseSource: 'table:table-1',+ keyColumn: 'org_id',+ columnMappings,+ })++ expect(logic.values.profileMappingDisabledReason).toEqual(expectedReason)+ }+ )+describe('mapping every column at once', () => {const openWithColumns = async (formValues: Record<string, any>): Promise<void> => {// oxlint-disable-next-line react-hooks/rules-of-hooks@@ -455,16 +489,21 @@ describe('customPropertyDefinitionsLogic', () => {expect(logic.values.mappableColumns).toEqual([])})- it('never serializes the key column as a property, even after the key changes', async () => {+ it('never serializes the key column as a property, and says so on the row', async () => {// Bulk mapping excludes whatever key column is set at the time, but the key can change// afterwards. The column_property_map is create-only, so writing the new identifier column as- // a property would be unrecoverable, and it must be dropped from the payload.+ // a property would be unrecoverable, and it must be dropped from the payload. The row has to+ // report that, otherwise the mapping looks saved and then disappears.await mapAll({ keyColumn: 'org_id' })expect(logic.values.serializedColumnPropertyMap).toEqual({ mrr: 'mrr' })+ expect(logic.values.columnMappingWarnings).toEqual([null])logic.actions.setCustomPropertyFormValue('keyColumn', 'mrr')expect(logic.values.serializedColumnPropertyMap).toEqual({})+ expect(logic.values.columnMappingWarnings).toEqual([+ `"mrr" is the distinct ID column, so this mapping isn't saved. Map a different column.`,+ ])})it('leaves the key column mappable until one is chosen', async () => {diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.tsindex 40928398c3fb..638c5cb0604c 100644--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts@@ -198,6 +198,11 @@ const serializeDefinition = ({// props are also warned on (see columnMappingWarnings). Warn-only — the user can still proceed.const RESERVED_PERSON_PROPERTY_NAMES = new Set(['email', 'name', 'username'])+// What the key column is called on screen. Shared so the field label, the mapping warning and the+// submit gate name the same thing.+export const keyColumnLabel = (targetType: CustomPropertyTargetType): string =>+ targetType === 'group' ? 'group key column' : 'distinct ID column'+// The backend stores column_property_map as a JSON object; the form edits it as an ordered list.// Descriptions are stored in a parallel {column: description} object and folded back in per column.const parseColumnPropertyMap = (value: unknown, descriptions: unknown): ColumnPropertyMapping[] => {@@ -254,6 +259,7 @@ export interface customPropertyDefinitionsLogicValues {newWorkflowUrlLoading: booleanpersonPropertyDefinitions: PropertyDefinition[]personPropertyDefinitionsLoading: boolean+ profileMappingDisabledReason: string | undefinedprofileSourceBinding: ProfileSourceBinding | nullrunsBySourceId: Record<string, CustomPropertySyncRunApi[]>runsCountBySourceId: Record<string, number>@@ -535,6 +541,11 @@ export interface customPropertyDefinitionsLogicMeta {) => WarehouseColumn[]serializedColumnPropertyMap: (customPropertyForm: CustomPropertyFormValues) => Record<string, string>serializedColumnDescriptions: (customPropertyForm: CustomPropertyFormValues) => Record<string, string>+ profileMappingDisabledReason: (+ customPropertyForm: CustomPropertyFormValues,+ editingDefinition: CustomPropertyDefinitionApi | null,+ serializedColumnPropertyMap: Record<string, string>+ ) => string | undefinedcolumnMappingWarnings: (customPropertyForm: CustomPropertyFormValues,personPropertyDefinitions: PropertyDefinition[]@@ -1140,13 +1151,46 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic)},],+ // Why a new person/group source can't be saved yet, or undefined once it can. The mapping+ // rows aren't LemonFields, so this gates the submit button rather than showing a per-field+ // error. It reads the serialized map instead of the rows on screen, because a row on the key+ // column is dropped from the payload: rows that all sit on the key column would otherwise+ // post an empty column_property_map, which the backend rejects after the definition itself+ // is already created.+ profileMappingDisabledReason: [+ (s) => [s.customPropertyForm, s.editingDefinition, s.serializedColumnPropertyMap],+ (+ form: CustomPropertyFormValues,+ editingDefinition: CustomPropertyDefinitionApi | null,+ serializedColumnPropertyMap: Record<string, string>+ ): string | undefined => {+ const isProfile = form.targetType === 'person' || form.targetType === 'group'+ // The column map is create-only on the backend, so an existing source has no+ // mapping left to gate.+ if (!isProfile || editingDefinition?.source || Object.keys(serializedColumnPropertyMap).length > 0) {+ return undefined+ }+ const hasCompleteRow = form.columnMappings.some(+ (mapping) => mapping.column.trim() && mapping.property.trim()+ )+ return hasCompleteRow+ ? `Map a column other than the ${keyColumnLabel(form.targetType)}`+ : 'Map at least one column to a property'+ },+ ],// Warn-only collision check per mapping: a chosen person-property name that is `$`-prefixed,- // an identity property, or already defined on persons could overwrite existing values.+ // an identity property, or already defined on persons could overwrite existing values. A row+ // on the key column is reported here too, because serializedColumnPropertyMap drops it.columnMappingWarnings: [(s) => [s.customPropertyForm, s.personPropertyDefinitions],(form: CustomPropertyFormValues, personPropertyDefinitions: PropertyDefinition[]): (string | null)[] => {const existing = new Set(personPropertyDefinitions.map((definition) => definition.name))+ const keyColumn = form.keyColumn?.trim()+ const keyColumnLabelText = keyColumnLabel(form.targetType)return form.columnMappings.map((mapping) => {+ if (keyColumn && mapping.column.trim() === keyColumn) {+ return `"${keyColumn}" is the ${keyColumnLabelText}, so this mapping isn't saved. Map a different column.`+ }const name = mapping.property.trim()if (!name) {return null