: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(batch-exports): move compression reset out of render-prop effect (#62194)
Paul D'Ambra72b109fede26
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsxindex dd477040ef35..6bdf2c5bfeb8 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx@@ -39,7 +39,6 @@ export function BatchExportConfiguration(): JSX.Element {batchExportConfigTest,batchExportConfigTestLoading,configuration,- configurationChanged,tables,batchExportConfig,selectedModel,@@ -360,7 +359,6 @@ export function BatchExportConfiguration(): JSX.Element {<BatchExportConfigurationFieldsisNew={isNew}formValues={configuration as BatchExportConfigurationForm}- configurationChanged={configurationChanged}/></div>{batchExportConfigTest && (@@ -387,20 +385,14 @@ export function BatchExportConfiguration(): JSX.Element {function BatchExportConfigurationFields({isNew,formValues,- configurationChanged,}: {isNew: booleanformValues: BatchExportConfigurationForm- configurationChanged: boolean}): JSX.Element {return (<><BatchExportGeneralEditFields isNew={isNew} isPipeline batchExportConfigForm={formValues} />- <BatchExportsEditFields- isNew={isNew}- batchExportConfigForm={formValues}- configurationChanged={configurationChanged}- />+ <BatchExportsEditFields isNew={isNew} batchExportConfigForm={formValues} /></>)}diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsxindex 25304ac63118..4236760c1ea8 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx@@ -79,24 +79,16 @@ export function BatchExportGeneralEditFields({export function BatchExportsEditFields({isNew,batchExportConfigForm,- configurationChanged,}: {isNew: booleanbatchExportConfigForm: BatchExportConfigurationForm- configurationChanged: boolean}): JSX.Element {const destination = batchExportConfigForm.destinationconst definition = destination ? DESTINATIONS[destination] : undefinedreturn (<div className="flex flex-col gap-y-4 max-w-200">- {definition && (- <definition.Fields- isNew={isNew}- formValues={batchExportConfigForm}- configurationChanged={configurationChanged}- />- )}+ {definition && <definition.Fields isNew={isNew} formValues={batchExportConfigForm} />}</div>)}diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.tsindex 584330b4d358..cf3cfbb21216 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts@@ -545,6 +545,87 @@ describe('batchExportConfigFormLogic', () => {})})+ describe('compression resets when file_format changes', () => {+ it.each([+ { newFormat: 'JSONLines', expected: null },+ { newFormat: 'Parquet', expected: 'zstd' },+ ])('new export: switching to $newFormat sets compression to $expected', async ({ newFormat, expected }) => {+ await initLogic({ service: 'S3', id: null })++ logic.actions.setConfigurationValue('file_format', newFormat)+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.configuration.compression).toBe(expected)+ })++ it.each([+ { startCompression: 'snappy', expected: null },+ { startCompression: 'gzip', expected: 'gzip' },+ ])(+ 'existing export: Parquet/$startCompression -> JSONLines yields $expected',+ async ({ startCompression, expected }) => {+ await initLogic({ service: null, id: S3_BATCH_EXPORT.id })+ logic.actions.setConfigurationValues({ compression: startCompression })+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.setConfigurationValue('file_format', 'JSONLines')+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.configuration.compression).toBe(expected)+ }+ )++ it('existing export: Parquet/zstd -> JSONLines -> Parquet restores the saved zstd codec', async () => {+ // AWS_S3_BATCH_EXPORT is saved with Parquet/zstd; zstd is invalid for JSONLines, so it's+ // cleared on the way out and must come back from the saved config — not default to zstd by+ // coincidence.+ await initLogic({ service: null, id: AWS_S3_BATCH_EXPORT.id })+ expect(logic.values.configuration.compression).toBe('zstd')++ logic.actions.setConfigurationValue('file_format', 'JSONLines')+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.configuration.compression).toBeNull()++ logic.actions.setConfigurationValue('file_format', 'Parquet')+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.configuration.compression).toBe('zstd')+ })++ it('existing export: Parquet/gzip survives a JSONLines round-trip (valid for both formats)', async () => {+ await initLogic({ service: null, id: S3_BATCH_EXPORT.id })+ expect(logic.values.configuration.compression).toBe('gzip')++ logic.actions.setConfigurationValue('file_format', 'JSONLines')+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.configuration.compression).toBe('gzip')++ logic.actions.setConfigurationValue('file_format', 'Parquet')+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.configuration.compression).toBe('gzip')+ })+ })++ describe('invalid persisted compression is dropped on save', () => {+ it('clears a JSONLines+zstd combination when saving an unrelated edit', async () => {+ await initLogic({ service: null, id: S3_BATCH_EXPORT.id })++ logic.actions.setConfigurationValues({+ ...logic.values.configuration,+ file_format: 'JSONLines',+ compression: 'zstd',+ prefix: 'updated-prefix/',+ })++ await expectLogic(logic, () => {+ logic.actions.submitConfiguration()+ }).toDispatchActions(['submitConfiguration', 'updateBatchExportConfigSuccess'])++ expect(lastPatchBody!.destination.config.file_format).toBe('JSONLines')+ expect(lastPatchBody!.destination.config.compression).toBeNull()+ expect(lastPatchBody!.destination.config.prefix).toBe('updated-prefix/')+ })+ })+describe('Redshift bucket validation only runs in COPY mode', () => {// Validates that Redshift's mode-conditional validation only kicks in for COPY mode.// INSERT mode shouldn't validate the (irrelevant) bucket name field.diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsxindex 73bf41006129..ede81ac05cdb 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx@@ -21,7 +21,7 @@ import {import type { batchExportConfigFormLogicType } from './batchExportConfigFormLogicType'import { batchExportDataLogic } from './batchExportDataLogic'import { DESTINATIONS } from './destinations'-import { genericPersonEventFields } from './destinations/common'+import { genericPersonEventFields, isSelectedCompressionOptionValid } from './destinations/common'import { humanizeBatchExportName } from './utils'export interface BatchExportConfigFormLogicProps {@@ -73,6 +73,12 @@ function buildDestinationPayload(formValues: Record<string, any>): {}config[key] = value}+ // A persisted compression value can be invalid for the selected file_format (e.g. an+ // externally-created JSONLines export still carrying a Parquet-only codec). Drop it on save so+ // editing an unrelated field doesn't resubmit a combination the backend rejects.+ if ('compression' in config && !isSelectedCompressionOptionValid(config.file_format, config.compression)) {+ config.compression = null+ }const result: { type: string; config: Record<string, any>; integration?: any } = {type: destinationType,config,@@ -841,6 +847,28 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([setConfigurationValue: ({ name, value }) => {const fieldName = Array.isArray(name) ? name[0] : name+ if (fieldName === 'file_format') {+ // Pick a compression that's valid for the newly-selected format, in priority order:+ // 1. keep the current codec if it still fits (e.g. gzip works for both formats);+ // 2. otherwise, when returning to the format the export was saved with, restore the+ // persisted codec — so a Parquet→JSONLines→Parquet round-trip recovers the saved+ // compression rather than stranding the export on a default;+ // 3. otherwise fall back to the format's default (zstd for Parquet, none for JSONLines).+ const current = values.configuration.compression+ const saved = values.savedConfiguration+ let next: string | null+ if (current !== null && isSelectedCompressionOptionValid(value, current)) {+ next = current+ } else if (value === saved.file_format && isSelectedCompressionOptionValid(value, saved.compression)) {+ next = saved.compression+ } else {+ next = value === 'Parquet' ? 'zstd' : null+ }+ if (next !== current) {+ actions.setConfigurationValue('compression', next)+ }+ }+if (fieldName === 'interval') {// if changing to day or week, set the timezone to the team's timezone if not already setif (value === 'day' || value === 'week') {diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/awss3.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/awss3.tsxindex 5b8554b0cd32..b914dc0b09b5 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/awss3.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/awss3.tsx@@ -27,12 +27,11 @@ export const awsS3Definition: DestinationDefinition = {}),eventTableExtraFields: S3_FAMILY_EVENT_TABLE_EXTRA_FIELDS,eventTableOverrides: { includeGenericPersonFields: false },- Fields: function AwsS3Fields({ isNew, formValues, configurationChanged }) {+ Fields: function AwsS3Fields({ isNew, formValues }) {return (<S3FamilyFieldsisNew={isNew}formValues={formValues}- configurationChanged={configurationChanged}regionOptions={AWS_ONLY_REGION_OPTIONS}awsBrandedshowEncryptiondiff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsxindex f8ab576168b6..ef4ac11617bb 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx@@ -19,7 +19,7 @@ export const azureBlobDefinition: DestinationDefinition = {container_name: validateAzureContainerName(formValues.container_name),}),eventTableOverrides: { teamIdHogql: 'team_id' },- Fields: function AzureBlobFields({ isNew, formValues, configurationChanged }) {+ Fields: function AzureBlobFields({ formValues }) {return (<><LemonField name="integration_id" label="Azure connection">@@ -60,11 +60,7 @@ export const azureBlobDefinition: DestinationDefinition = {<MaxFileSizeField /></div>- <CompressionField- fileFormat={formValues.file_format}- isNew={isNew}- configurationChanged={configurationChanged}- />+ <CompressionField fileFormat={formValues.file_format} /></>)},diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsxindex 2365eceffa2b..0172e8e6136c 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx@@ -1,4 +1,4 @@-import React, { type ReactNode } from 'react'+import { type ReactNode } from 'react'import { LemonCheckbox, LemonInput, LemonSelect, Link } from '@posthog/lemon-ui'@@ -203,58 +203,32 @@ const JSONLINES_COMPRESSION_OPTIONS = [{ value: null, label: 'No compression' },]-// Compression select that adapts its options to the currently-selected file format and self-corrects-// invalid combinations. Used by S3 and AzureBlob, which share file_format/compression semantics.-export function CompressionField({- fileFormat,- isNew,- configurationChanged,-}: {- fileFormat: string | undefined- isNew: boolean- configurationChanged: boolean-}): JSX.Element {+export function isSelectedCompressionOptionValid(fileFormat: string | undefined, value: string | null): boolean {+ if (fileFormat === 'Parquet') {+ return PARQUET_COMPRESSION_OPTIONS.some((option) => option.value === value)+ } else if (fileFormat === 'JSONLines') {+ return JSONLINES_COMPRESSION_OPTIONS.some((option) => option.value === value)+ }+ return false+}++// Compression select whose options adapt to the currently-selected file format. Used by S3 and+// AzureBlob, which share file_format/compression semantics. The form logic resets compression to a+// valid value when file_format changes (see batchExportConfigFormLogic's setConfigurationValue).+export function CompressionField({ fileFormat }: { fileFormat: string | undefined }): JSX.Element {+ const compressionOptions =+ fileFormat === 'Parquet'+ ? PARQUET_COMPRESSION_OPTIONS+ : fileFormat === 'JSONLines'+ ? JSONLINES_COMPRESSION_OPTIONS+ : []+return (<LemonField name="compression" label="Compression" className="flex-1">- {({ value, onChange }) => {- const compressionOptions =- fileFormat === 'Parquet'- ? PARQUET_COMPRESSION_OPTIONS- : fileFormat === 'JSONLines'- ? JSONLINES_COMPRESSION_OPTIONS- : []-- const isSelectedCompressionOptionValid = (val: string | null): boolean => {- if (fileFormat === 'Parquet') {- return PARQUET_COMPRESSION_OPTIONS.some((option) => option.value === val)- } else if (fileFormat === 'JSONLines') {- return JSONLINES_COMPRESSION_OPTIONS.some((option) => option.value === val)- }- return false- }-- React.useEffect(() => {- if (!configurationChanged) {- return- }- if (isNew && fileFormat === 'JSONLines') {- onChange(null)- } else if (isNew && fileFormat === 'Parquet') {- onChange('zstd')- } else if (!isSelectedCompressionOptionValid(value)) {- onChange(null)- }- }, [configurationChanged, fileFormat, isNew]) // oxlint-disable-line react-hooks/exhaustive-deps-- return (- <LemonSelect- options={compressionOptions}- value={value}- onChange={onChange}- placeholder={!fileFormat ? 'Select file format first' : undefined}- />- )- }}+ <LemonSelect+ options={compressionOptions}+ placeholder={!fileFormat ? 'Select file format first' : undefined}+ /></LemonField>)}@@ -314,7 +288,6 @@ export const S3_FAMILY_EVENT_TABLE_EXTRA_FIELDS: Record<string, DatabaseSchemaFiexport function S3FamilyFields({isNew,formValues,- configurationChanged,regionOptions,awsBranded,allowCustomRegion = false,@@ -326,7 +299,6 @@ export function S3FamilyFields({}: {isNew: booleanformValues: Record<string, any>- configurationChanged: booleanregionOptions: { value: string; label: string }[]// Prefix the credential labels with "AWS" — only true for AWS S3, not the S3-compatible catch-all.awsBranded: boolean@@ -388,11 +360,7 @@ export function S3FamilyFields({</div><div className="flex gap-4">- <CompressionField- fileFormat={formValues.file_format}- isNew={isNew}- configurationChanged={configurationChanged}- />+ <CompressionField fileFormat={formValues.file_format} />{showEncryption && (<LemonField name="encryption" label="Encryption" className="flex-1">diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsxindex 824397f203b0..b97d979c28a7 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx@@ -23,12 +23,11 @@ export const s3Definition: DestinationDefinition = {}),eventTableExtraFields: S3_FAMILY_EVENT_TABLE_EXTRA_FIELDS,eventTableOverrides: { includeGenericPersonFields: false },- Fields: function S3Fields({ isNew, formValues, configurationChanged }) {+ Fields: function S3Fields({ isNew, formValues }) {return (<S3FamilyFieldsisNew={isNew}formValues={formValues}- configurationChanged={configurationChanged}regionOptions={S3_REGION_OPTIONS}awsBrandedallowCustomRegiondiff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3compatible.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3compatible.tsxindex 0139dd688aea..0ed9febb8663 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3compatible.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3compatible.tsx@@ -23,12 +23,11 @@ export const s3CompatibleDefinition: DestinationDefinition = {}),eventTableExtraFields: S3_FAMILY_EVENT_TABLE_EXTRA_FIELDS,eventTableOverrides: { includeGenericPersonFields: false },- Fields: function S3CompatibleFields({ isNew, formValues, configurationChanged }) {+ Fields: function S3CompatibleFields({ isNew, formValues }) {return (<S3FamilyFieldsisNew={isNew}formValues={formValues}- configurationChanged={configurationChanged}regionOptions={S3_REGION_OPTIONS}awsBranded={false}allowCustomRegiondiff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts b/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.tsindex e219cdf2726f..4defc3678696 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts@@ -40,5 +40,5 @@ export interface DestinationDefinition {eventTableOverrides?: EventTableOverrides// Lift integration_id from destination.integration during deserialize and push it back during save.usesIntegration?: boolean- Fields: React.FC<{ isNew: boolean; formValues: Record<string, any>; configurationChanged: boolean }>+ Fields: React.FC<{ isNew: boolean; formValues: Record<string, any> }>}