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(flags): BigInt serialization error on feature flag copy failure (#80814)

Phil Haack64bd55f5a071
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
index 18f56527d128..8eb71707456b 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
@@ -16,6 +16,7 @@ import { dayjs } from 'lib/dayjs'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { urls } from 'scenes/urls'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
@@ -35,7 +36,10 @@ import {
import { FeatureFlagFilters } from '~/types'
import { TemplateKey } from 'products/feature_flags/frontend/featureFlagTemplateConstants'
-import type { CopyFlagsDependencyRequirementsResponseApi } from 'products/feature_flags/frontend/generated/api.schemas'
+import type {
+ CopyFlagsDependencyRequirementsResponseApi,
+ CopyFlagsResponseApi,
+} from 'products/feature_flags/frontend/generated/api.schemas'
import * as defaultReleaseConditionsModule from './defaultReleaseConditionsLogic'
import {
@@ -1882,6 +1886,9 @@ describe('featureFlagLogic', () => {
],
},
})
+ // The copy listener reports to eventUsageLogic, but featureFlagLogic does not mount it via connect().
+ // Mount it here so the listener does not throw when it calls reportFeatureFlagCopyFailure().
+ eventUsageLogic.mount()
logic.actions.setCopyDestinationProject(MOCK_TEAM_ID)
})
@@ -1933,6 +1940,22 @@ describe('featureFlagLogic', () => {
expect(lemonToast.error).toHaveBeenCalledWith('Error while copying feature flag: Project not found.')
expect(lemonToast.warning).not.toHaveBeenCalled()
})
+
+ it('serializes BigInt payload values in the error toast when a failure has no error_message', async () => {
+ // JSON transport can't carry a BigInt, so the HTTP mock layer can't produce this
+ // payload — dispatch the loader success action directly with the shape the
+ // stringifyWithBigInts fallback defends against.
+ logic.actions.copyFlagSuccess({
+ success: [],
+ failed: [{ project_id: MOCK_TEAM_ID, filter_value: BigInt(123) }],
+ } as unknown as CopyFlagsResponseApi)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(lemonToast.error).toHaveBeenCalledWith(
+ `Error while copying feature flag: [{"project_id":${MOCK_TEAM_ID},"filter_value":"123"}]`
+ )
+ expect(lemonToast.warning).not.toHaveBeenCalled()
+ })
})
})
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
index d8f3d484ed3d..cb30b2cf0450 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
@@ -35,6 +35,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { stringifyWithBigInts } from 'lib/utils/json'
import { objectsEqual } from 'lib/utils/objects'
import { slugify } from 'lib/utils/strings'
import { experimentLogic } from 'scenes/experiments/experimentLogic'
@@ -3724,7 +3725,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
eventUsageLogic.actions.reportFeatureFlagCopyFailure(failure.error_message ?? 'Approval pending')
} else {
const errorMessage =
- failure?.error_message ?? JSON.stringify(featureFlagCopy?.failed ?? featureFlagCopy)
+ failure?.error_message ?? stringifyWithBigInts(featureFlagCopy?.failed ?? featureFlagCopy)
lemonToast.error(`Error while copying feature flag: ${errorMessage}`)
eventUsageLogic.actions.reportFeatureFlagCopyFailure(errorMessage)
}