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(batch-exports): show an error when saving fails (#88603)

Tomás Farías Santana433bd26bb53f
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
index 215ebc82c0f1..af22743412ac 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
@@ -1,6 +1,8 @@
import { router } from 'kea-router'
import { expectLogic, partial } from 'kea-test-utils'
+import { lemonToast } from '@posthog/lemon-ui'
+
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -307,7 +309,11 @@ const ALL_BATCH_EXPORTS: BatchExportConfiguration[] = [
AZUREBLOB_BATCH_EXPORT,
]
-jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({
+const SAVE_FAILS_ID = 'test-save-fails-id'
+const SAVE_FAILS_DETAIL = 'Prefix is not valid'
+
+jest.mock('@posthog/lemon-ui', () => ({
+ ...jest.requireActual('@posthog/lemon-ui'),
lemonToast: {
error: jest.fn(),
success: jest.fn(),
@@ -343,6 +349,13 @@ describe('batchExportConfigFormLogic', () => {
return [200, fx]
}
}
+ // Same shape as the AwsS3 fixture, but its PATCH always fails, for the save-error path.
+ getMocks[`/api/environments/:team_id/batch_exports/${SAVE_FAILS_ID}`] = {
+ ...AWS_S3_BATCH_EXPORT,
+ id: SAVE_FAILS_ID,
+ }
+ patchMocks[`/api/environments/:team_id/batch_exports/${SAVE_FAILS_ID}/`] = async () =>
+ [400, { detail: SAVE_FAILS_DETAIL }] as unknown as [number, BatchExportConfiguration]
useMocks({
get: {
...getMocks,
@@ -692,6 +705,29 @@ describe('batchExportConfigFormLogic', () => {
})
})
+ describe('failed update', () => {
+ // A rejected save produced no toast and no inline error, so the button appeared to do
+ // nothing. The edits stay on the form for a retry, which makes the toast the only signal
+ // the user gets.
+ it('surfaces the API error and keeps the unsaved changes', async () => {
+ await initLogic({ service: null, id: SAVE_FAILS_ID })
+
+ logic.actions.setConfigurationValues({
+ ...logic.values.configuration,
+ prefix: 'updated-prefix/',
+ })
+
+ await expectLogic(logic, () => {
+ logic.actions.submitConfiguration()
+ })
+ .toDispatchActions(['submitConfiguration', 'submitConfigurationSuccess'])
+ .toFinishAllListeners()
+
+ expect(lemonToast.error).toHaveBeenCalledWith(SAVE_FAILS_DETAIL)
+ expect(logic.values.configurationChanged).toBe(true)
+ })
+ })
+
describe('getDefaultConfiguration', () => {
it.each([
{
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
index 05ac13c81212..4e795dc67388 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
@@ -1023,28 +1023,34 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
destination: buildDestinationPayload(formdata) as any,
} as any
- if (props.id) {
- const res = await api.batchExports.update(props.id, data)
- lemonToast.success('Batch export configuration updated successfully')
+ try {
+ if (props.id) {
+ const res = await api.batchExports.update(props.id, data)
+ lemonToast.success('Batch export configuration updated successfully')
+ void addProductIntent({
+ product_type: ProductKey.PIPELINE_BATCH_EXPORTS,
+ intent_context: ProductIntentContext.BATCH_EXPORT_UPDATED,
+ })
+ actions.setBatchExportConfig(res)
+ actions.updateBatchExportConfigSuccess(res)
+ return
+ }
+ const res = await api.batchExports.create(data)
+ actions.resetConfiguration(getConfigurationFromBatchExportConfig(res))
+
void addProductIntent({
product_type: ProductKey.PIPELINE_BATCH_EXPORTS,
- intent_context: ProductIntentContext.BATCH_EXPORT_UPDATED,
+ intent_context: ProductIntentContext.BATCH_EXPORT_CREATED,
})
- actions.setBatchExportConfig(res)
+
+ router.actions.replace(urls.batchExport(res.id))
+ lemonToast.success('Batch export created successfully')
actions.updateBatchExportConfigSuccess(res)
- return
+ } catch (error: any) {
+ // Not rethrown, matching `deleteBatchExport` below: the unsaved values stay on the
+ // form either way, and a rejecting listener escapes kea as an unhandled rejection.
+ lemonToast.error(error.detail || error.message || 'Could not save the batch export. Try again.')
}
- const res = await api.batchExports.create(data)
- actions.resetConfiguration(getConfigurationFromBatchExportConfig(res))
-
- void addProductIntent({
- product_type: ProductKey.PIPELINE_BATCH_EXPORTS,
- intent_context: ProductIntentContext.BATCH_EXPORT_CREATED,
- })
-
- router.actions.replace(urls.batchExport(res.id))
- lemonToast.success('Batch export created successfully')
- actions.updateBatchExportConfigSuccess(res)
},
updateBatchExportConfigSuccess: ({ batchExportConfig }) => {
if (!batchExportConfig) {