: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(insights): guard funnel breakdown against out-of-enum types (#71637)
posthog[bot]09a219ca5cdb
diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.tsindex 43cc428b6ec6..84aa4a0838b9 100644--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts@@ -191,6 +191,23 @@ describe('taxonomicBreakdownFilterLogic', () => {})})+ it('rejects a taxonomic group that maps to a non-breakdown type', async () => {+ logic = taxonomicBreakdownFilterLogic(makeProps({ breakdownFilter: {} }))+ logic.mount()+ // Error tracking issues map to the `error_tracking_issue` property filter type, which is+ // not a valid `BreakdownType`. It must not reach the query as a breakdown.+ const group: TaxonomicFilterGroup = taxonomicGroupFor(+ TaxonomicFilterGroupType.ErrorTrackingIssues,+ undefined+ )++ await expectLogic(logic, () => {+ logic.actions.addBreakdown('some-issue', group)+ }).toFinishListeners()++ expect(updateBreakdownFilter).not.toHaveBeenCalled()+ })+it('sets a hide other aggregation', async () => {logic = taxonomicBreakdownFilterLogic(makeProps({ breakdownFilter: {} }))logic.mount()diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.tsindex ba17c9f6f3c4..d6f9eb03dbb6 100644--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts@@ -16,12 +16,17 @@ import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'import { Breakdown, BreakdownFilter } from '~/queries/schema/schema-general'-import { BreakdownType, ChartDisplayType, InsightLogicProps } from '~/types'+import { ChartDisplayType, InsightLogicProps } from '~/types'import type { FeatureFlagsSet } from '../../../../lib/logic/featureFlagLogic'import type { DatabaseSchemaField } from '../../../../queries/schema/schema-general'import type { PropertyDefinition, PropertyDefinitionType } from '../../../../types'-import { isCohortBreakdown, isMultipleBreakdownType, isURLNormalizeable } from './taxonomicBreakdownFilterUtils'+import {+ isBreakdownType,+ isCohortBreakdown,+ isMultipleBreakdownType,+ isURLNormalizeable,+} from './taxonomicBreakdownFilterUtils'// Kept in sync with the `@maxItems` on `BreakdownFilter.breakdowns` in schema-general.ts.const MAX_TRENDS_BREAKDOWNS = 3@@ -548,7 +553,8 @@ export const taxonomicBreakdownFilterLogic = kea<taxonomicBreakdownFilterLogicTy}),listeners(({ props, values, actions }) => ({addBreakdown: ({ breakdown, taxonomicGroup }) => {- const breakdownType = taxonomicFilterTypeToPropertyFilterType(taxonomicGroup.type) as BreakdownType+ const propertyFilterType = taxonomicFilterTypeToPropertyFilterType(taxonomicGroup.type)+ const breakdownType = isBreakdownType(propertyFilterType) ? propertyFilterType : undefinedconst propertyDefinitionType = propertyFilterTypeToPropertyDefinitionType(breakdownType)const isHistogramable =!!values.getPropertyDefinition(breakdown, propertyDefinitionType)?.is_numerical && props.isTrends@@ -701,9 +707,10 @@ export const taxonomicBreakdownFilterLogic = kea<taxonomicBreakdownFilterLogicTy}},replaceBreakdown: ({ previousBreakdown, newBreakdown }) => {- const breakdownType = taxonomicFilterTypeToPropertyFilterType(newBreakdown.group.type) as- | BreakdownType- | undefined+ const newBreakdownPropertyFilterType = taxonomicFilterTypeToPropertyFilterType(newBreakdown.group.type)+ const breakdownType = isBreakdownType(newBreakdownPropertyFilterType)+ ? newBreakdownPropertyFilterType+ : undefinedconst breakdownValue = newBreakdown.valueconst propertyDefinitionType = propertyFilterTypeToPropertyDefinitionType(breakdownType)diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.tsindex f69668c87c3f..29064f58b054 100644--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts@@ -23,3 +23,22 @@ export function isMultipleBreakdownType(breakdownType?: BreakdownType | null): b]return !!breakdownType && (types as string[]).includes(breakdownType)}++// Not every taxonomic/property filter type is a valid breakdown type. Casting one straight to+// `BreakdownType` lets an unsupported value (e.g. a legacy `"property"`) reach the query, where the+// backend rejects it with a dead-end error. Guard the value against the enum instead of casting.+export function isBreakdownType(breakdownType?: string | null): breakdownType is BreakdownType {+ const types: BreakdownType[] = [+ 'cohort',+ 'person',+ 'event',+ 'event_metadata',+ 'group',+ 'session',+ 'hogql',+ 'data_warehouse',+ 'data_warehouse_person_property',+ 'revenue_analytics',+ ]+ return !!breakdownType && (types as string[]).includes(breakdownType)+}diff --git a/posthog/hogql_queries/insights/funnels/funnel_event_query.py b/posthog/hogql_queries/insights/funnels/funnel_event_query.pyindex 2c617cfe2835..d2636b5b8f55 100644--- a/posthog/hogql_queries/insights/funnels/funnel_event_query.py+++ b/posthog/hogql_queries/insights/funnels/funnel_event_query.py@@ -485,7 +485,12 @@ class FunnelEventQuery(DataWarehouseSchemaMixin):elif breakdownType == "data_warehouse":return get_breakdown_expr(breakdown, None)else:- raise ValidationError(detail=f"Unsupported breakdown type: {breakdownType}")+ raise ValidationError(+ detail=(+ f'"{breakdownType}" is not a supported breakdown type for funnels. '+ "Remove the breakdown or pick a different property to continue."+ )+ )def _query_has_array_breakdown(self) -> bool:breakdown, breakdownType = self.context.breakdown, self.context.breakdownType