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(insights): don't crash insight scene on unsupported query kinds (#63188)

Christiaan Hendriksen848f99104b8a
diff --git a/frontend/src/scenes/insights/insightDataLogic.test.ts b/frontend/src/scenes/insights/insightDataLogic.test.ts
index 682682290c94..388af5f5bfe0 100644
--- a/frontend/src/scenes/insights/insightDataLogic.test.ts
+++ b/frontend/src/scenes/insights/insightDataLogic.test.ts
@@ -11,6 +11,7 @@ import { insightLogic } from 'scenes/insights/insightLogic'
import { useMocks } from '~/mocks/jest'
import { examples } from '~/queries/examples'
+import { getDefaultQuery } from '~/queries/nodes/InsightViz/utils'
import { performQuery } from '~/queries/query'
import {
FunnelsQuery,
@@ -20,7 +21,7 @@ import {
TrendsQuery,
} from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { FunnelVizType, InsightShortId } from '~/types'
+import { FunnelVizType, InsightShortId, InsightType } from '~/types'
import { insightDataLogic } from './insightDataLogic'
@@ -128,6 +129,40 @@ describe('insightDataLogic', () => {
})
})
+ describe('queryChanged', () => {
+ const tracesQuery = {
+ kind: NodeKind.InsightVizNode,
+ source: { kind: NodeKind.TracesQuery },
+ } as unknown as InsightVizNode
+
+ const doubleWrappedDataVisualizationQuery = {
+ kind: NodeKind.InsightVizNode,
+ source: {
+ kind: NodeKind.DataVisualizationNode,
+ source: { kind: NodeKind.HogQLQuery, query: 'select 1' },
+ },
+ } as unknown as InsightVizNode
+
+ it.each([
+ ['TracesQuery', tracesQuery],
+ ['DataVisualizationNode', doubleWrappedDataVisualizationQuery],
+ ])('treats an InsightVizNode wrapping an unsupported %s source as changed', async (_, query) => {
+ await expectLogic(theInsightDataLogic, () => {
+ theInsightDataLogic.actions.setQuery(query)
+ }).toMatchValues({ queryChanged: true })
+ })
+
+ it('treats the default query of a supported source kind as unchanged', async () => {
+ const defaultTrendsQuery = getDefaultQuery(
+ InsightType.TRENDS,
+ theInsightDataLogic.values.filterTestAccountsDefault
+ )
+ await expectLogic(theInsightDataLogic, () => {
+ theInsightDataLogic.actions.setQuery(defaultTrendsQuery)
+ }).toMatchValues({ queryChanged: false })
+ })
+ })
+
describe('cached insight query sync', () => {
const baseQuery = examples.InsightTrends as InsightVizNode
const trendsSource = baseQuery.source as TrendsQuery
diff --git a/frontend/src/scenes/insights/insightDataLogic.tsx b/frontend/src/scenes/insights/insightDataLogic.tsx
index 31bee791b6d7..b4920a7b1d00 100644
--- a/frontend/src/scenes/insights/insightDataLogic.tsx
+++ b/frontend/src/scenes/insights/insightDataLogic.tsx
@@ -201,6 +201,11 @@ export const insightDataLogic = kea<insightDataLogicType>([
if (isWebAnalyticsInsightQuery(query.source)) {
return true
}
+ // Source kinds without a product analytics default (e.g. a TracesQuery from an
+ // AI-generated link) have no default to compare against, so treat as changed
+ if (!(query.source.kind in nodeKindToInsightType)) {
+ return true
+ }
const insightType = nodeKindToInsightType[query.source.kind]
savedOrDefaultQuery = getDefaultQuery(insightType, filterTestAccountsDefault)
} else if (isDataVisualizationNode(query)) {