: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): save csv quote handling when editing a self-managed table (#109658)
Tom Owers41debc7d6c8d
diff --git a/frontend/src/scenes/data-pipelines/DataPipelinesSelfManagedSource.tsx b/frontend/src/scenes/data-pipelines/DataPipelinesSelfManagedSource.tsxindex 0c2357fc9d64..355da239c139 100644--- a/frontend/src/scenes/data-pipelines/DataPipelinesSelfManagedSource.tsx+++ b/frontend/src/scenes/data-pipelines/DataPipelinesSelfManagedSource.tsx@@ -3,7 +3,10 @@ import { BindLogic, useActions, useValues } from 'kea'import { DataWarehouseTable } from '~/types'import { SelfManagedSourceForm } from 'products/data_warehouse/frontend/scenes/NewSourceScene/components/SelfManagedSourceForm'-import { selfManagedSourceLogic } from 'products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic'+import {+ selfManagedSourceLogic,+ selfManagedTableUpdatePayload,+} from 'products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic'interface SelfManagedProps {id: string@@ -29,27 +32,7 @@ export function DataPipelinesSelfManagedSourceTable({ table, updateTable }: Propreturn (<><div className="deprecated-space-y-4">- <SelfManagedSourceForm- onUpdate={() =>- updateTable({- name: table.name,- url_pattern: table.url_pattern,- format: table.format,- ...(table.credential?.access_key || table.credential?.access_secret- ? {- credential: {- ...(table.credential?.access_key- ? { access_key: table.credential.access_key }- : {}),- ...(table.credential?.access_secret- ? { access_secret: table.credential.access_secret }- : {}),- },- }- : {}),- })- }- />+ <SelfManagedSourceForm onUpdate={() => updateTable(selfManagedTableUpdatePayload(table))} /></div></>)diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.test.tsindex 300ec47b55ee..535f174bd7c7 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.test.ts@@ -1,6 +1,6 @@import { DataWarehouseTable } from '~/types'-import { selfManagedTableFormErrors } from './selfManagedSourceLogic'+import { selfManagedTableFormErrors, selfManagedTableUpdatePayload } from './selfManagedSourceLogic'const validTable: Partial<DataWarehouseTable> = {name: 'stripe_invoices',@@ -9,40 +9,64 @@ const validTable: Partial<DataWarehouseTable> = {credential: { access_key: 'key', access_secret: 'secret' },}-describe('selfManagedTableFormErrors', () => {- // The API serves `credential: null` for tables saved without one (e.g. created by a- // managed pipeline) — reading through it used to crash the source scene.- it('validates a table with a null credential instead of throwing', () => {- const errors = selfManagedTableFormErrors({ ...validTable, credential: null })+describe('selfManagedSourceLogic', () => {+ describe('selfManagedTableFormErrors', () => {+ // The API serves `credential: null` for tables saved without one (e.g. created by a+ // managed pipeline) — reading through it used to crash the source scene.+ it('validates a table with a null credential instead of throwing', () => {+ const errors = selfManagedTableFormErrors({ ...validTable, credential: null })- expect(errors.credential).toEqual({- access_key: 'Please enter an access key.',- access_secret: 'Please enter an access secret.',+ expect(errors.credential).toEqual({+ access_key: 'Please enter an access key.',+ access_secret: 'Please enter an access secret.',+ })+ expect(errors.name).toBeFalsy()+ expect(errors.url_pattern).toBeFalsy()+ expect(errors.format).toBeFalsy()+ })++ it('returns no errors for a fully valid table', () => {+ const errors = selfManagedTableFormErrors(validTable)++ expect(errors.name).toBeFalsy()+ expect(errors.url_pattern).toBeFalsy()+ expect(errors.format).toBeFalsy()+ expect(errors.credential).toEqual({ access_key: false, access_secret: false })})- expect(errors.name).toBeFalsy()- expect(errors.url_pattern).toBeFalsy()- expect(errors.format).toBeFalsy()- })- it('returns no errors for a fully valid table', () => {- const errors = selfManagedTableFormErrors(validTable)+ // The backend rejects any non-https url pattern; these should surface a frontend error instead+ // of falling through to the generic server-side message.+ it.each([+ ['s3://your-org/invoices/*.pqt'],+ ['http://your-org.s3.amazonaws.com/invoices/*.pqt'],+ ['s3a://your-org/invoices/*.pqt'],+ ['your-org.s3.amazonaws.com/invoices/*.pqt'],+ ])('rejects non-https url pattern %s', (url_pattern) => {+ const errors = selfManagedTableFormErrors({ ...validTable, url_pattern })- expect(errors.name).toBeFalsy()- expect(errors.url_pattern).toBeFalsy()- expect(errors.format).toBeFalsy()- expect(errors.credential).toEqual({ access_key: false, access_secret: false })+ expect(errors.url_pattern).toBeTruthy()+ })})- // The backend rejects any non-https url pattern; these should surface a frontend error instead- // of falling through to the generic server-side message.- it.each([- ['s3://your-org/invoices/*.pqt'],- ['http://your-org.s3.amazonaws.com/invoices/*.pqt'],- ['s3a://your-org/invoices/*.pqt'],- ['your-org.s3.amazonaws.com/invoices/*.pqt'],- ])('rejects non-https url pattern %s', (url_pattern) => {- const errors = selfManagedTableFormErrors({ ...validTable, url_pattern })-- expect(errors.url_pattern).toBeTruthy()+ describe('selfManagedTableUpdatePayload', () => {+ it.each([+ ['an uploaded file', null, undefined],+ ['a linked bucket', { access_key: 'key', access_secret: '' }, { access_key: 'key' }],+ ])('keeps the CSV quote handling when saving %s', (_label, credential, expectedCredential) => {+ const payload = selfManagedTableUpdatePayload({+ ...(validTable as DataWarehouseTable),+ format: 'CSVWithNames',+ options: { csv_allow_double_quotes: true },+ credential,+ })++ expect(payload).toEqual({+ name: 'stripe_invoices',+ url_pattern: 'https://your-org.s3.amazonaws.com/invoices/*.pqt',+ format: 'CSVWithNames',+ options: { csv_allow_double_quotes: true },+ ...(expectedCredential ? { credential: expectedCredential } : {}),+ })+ })})})diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.tsxindex b3bb502de1ab..2a46f4d9e28f 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/selfManagedSourceLogic.tsx@@ -11,7 +11,7 @@ import { databaseTableListLogic } from 'scenes/data-management/database/databaseimport { urls } from 'scenes/urls'import { DataTableNode } from '~/queries/schema/schema-general'-import { AnyPropertyFilter, DataWarehouseTable } from '~/types'+import { AnyPropertyFilter, DataWarehouseCredential, DataWarehouseTable } from '~/types'import { sourceSceneLogic } from '../SourceScene/SourceScene'@@ -83,6 +83,27 @@ export function selfManagedTableFormErrors({}}+export type SelfManagedTableUpdate = Pick<DataWarehouseTable, 'name' | 'url_pattern' | 'format' | 'options'> & {+ credential?: Partial<DataWarehouseCredential>+}++export function selfManagedTableUpdatePayload(table: DataWarehouseTable): SelfManagedTableUpdate {+ return {+ name: table.name,+ url_pattern: table.url_pattern,+ format: table.format,+ options: table.options,+ ...(table.credential?.access_key || table.credential?.access_secret+ ? {+ credential: {+ ...(table.credential?.access_key ? { access_key: table.credential.access_key } : {}),+ ...(table.credential?.access_secret ? { access_secret: table.credential.access_secret } : {}),+ },+ }+ : {}),+ }+}+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface selfManagedSourceLogicValues {dataTableQuery: DataTableNode | null