: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): align new-source prefix validation with the backend rule (#67853)
Tom Owers941d78e17767
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsxindex e172f67c08f5..15057ead72b2 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx@@ -1833,8 +1833,17 @@ export const getErrorsForFields = (if (!values?.prefix?.trim()) {errors['prefix'] = 'Please enter a name for this direct query source.'}- } else if (!/^[a-zA-Z0-9_-]*$/.test(values?.prefix ?? '')) {- errors['prefix'] = "Please enter a valid prefix (only letters, numbers, and '_' or '-')."+ } else {+ // Mirror the backend `validate_source_prefix` rules (which strip only underscores, not+ // whitespace) so an invalid prefix is caught here rather than after the create request.+ const prefix = values?.prefix ?? ''+ const cleaned = prefix.replace(/^_+|_+$/g, '')+ if (prefix && !cleaned) {+ errors['prefix'] = 'Prefix cannot consist of only underscores'+ } else if (cleaned && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(cleaned)) {+ errors['prefix'] =+ 'Prefix must contain only letters, numbers, and underscores, and start with a letter or underscore'+ }}// Payload errorsdiff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.tsindex e24c7c210440..2f4ca022781a 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts@@ -261,9 +261,24 @@ describe('sourceWizardLogic', () => {expect(res).toEqual({ payload: {} })})- it('returns errors for an invalid prefix', () => {- const res = getErrorsForFields([], { prefix: '@@@', payload: {} })- expect(res.prefix).toBeTruthy()+ // Warehouse-mode prefixes must satisfy the backend `validate_source_prefix` rules so an+ // invalid prefix is caught in the wizard rather than only after the create request fails.+ it.each([+ ['@@@', true],+ ['my-prefix', true], // hyphen — rejected by the backend, previously allowed here+ ['2things', true], // leading digit+ ['___', true], // only underscores+ [' my ', true], // backend strips only underscores, not whitespace+ ['my_prefix', false],+ ['_leading', false],+ ['', false], // empty prefix is allowed+ ])('validates warehouse-mode prefix %p', (prefix, expectError) => {+ const res = getErrorsForFields([], { prefix, payload: {} })+ if (expectError) {+ expect(res.prefix).toBeTruthy()+ } else {+ expect(res.prefix).toBeUndefined()+ }})it('requires name for direct mode', () => {