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(query-scan): insight banner fixes and persons-join false positive (#101790)

Sandy Spicer3981f331db21
diff --git a/frontend/src/queries/nodes/DataNode/QueryScanBanner.tsx b/frontend/src/queries/nodes/DataNode/QueryScanBanner.tsx
index d9e298600248..215dc8571124 100644
--- a/frontend/src/queries/nodes/DataNode/QueryScanBanner.tsx
+++ b/frontend/src/queries/nodes/DataNode/QueryScanBanner.tsx
@@ -28,7 +28,7 @@ export function QueryScanBanner({ queryScan, onFixWithAI, className }: QueryScan
<span className="text-xs text-secondary">{queryScanStatLine(summary)}</span>
{showFindings && (
<LemonBanner type="warning">
- <QueryScanFindingList findings={findings} />
+ <QueryScanFindingList findings={findings} dropBulletIfSingle />
{onFixWithAI && assistantPrompt && (
<LemonButton
className="mt-2"
diff --git a/frontend/src/queries/nodes/DataNode/QueryScanFindingList.tsx b/frontend/src/queries/nodes/DataNode/QueryScanFindingList.tsx
index d4aad3c780ec..b29875b987c7 100644
--- a/frontend/src/queries/nodes/DataNode/QueryScanFindingList.tsx
+++ b/frontend/src/queries/nodes/DataNode/QueryScanFindingList.tsx
@@ -13,7 +13,17 @@ function withInlineCode(message: string): JSX.Element {
)
}
-export function QueryScanFindingList({ findings }: { findings: QueryScanWarning[] }): JSX.Element {
+export interface QueryScanFindingListProps {
+ findings: QueryScanWarning[]
+ /** Drops the bullet for a single finding. Only where a sibling icon already marks it, e.g. inside a LemonBanner. */
+ dropBulletIfSingle?: boolean
+}
+
+export function QueryScanFindingList({ findings, dropBulletIfSingle }: QueryScanFindingListProps): JSX.Element {
+ if (dropBulletIfSingle && findings.length === 1) {
+ return <div>{withInlineCode(findings[0].message)}</div>
+ }
+
return (
<ul className="list-disc pl-5">
{findings.map((finding, index) => (
diff --git a/frontend/src/scenes/insights/InsightQueryScanBanner.tsx b/frontend/src/scenes/insights/InsightQueryScanBanner.tsx
index dd1fbc1384a9..ed212ef49f15 100644
--- a/frontend/src/scenes/insights/InsightQueryScanBanner.tsx
+++ b/frontend/src/scenes/insights/InsightQueryScanBanner.tsx
@@ -1,12 +1,23 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
+import { autoRunMaxPrompt } from 'scenes/max/maxPrompt'
+
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { DataNodeLogicProps, dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { QueryScanBanner } from '~/queries/nodes/DataNode/QueryScanBanner'
import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/insightVizKeys'
-import { InsightLogicProps } from '~/types'
+import { InsightLogicProps, SidePanelTab } from '~/types'
export function InsightQueryScanBanner({ insightProps }: { insightProps: InsightLogicProps }): JSX.Element {
const { queryScan } = useValues(dataNodeLogic({ key: insightVizDataNodeKey(insightProps) } as DataNodeLogicProps))
+ const { openSidePanel } = useActions(sidePanelStateLogic)
+
+ const askAssistant = (): void => {
+ if (!queryScan?.assistantPrompt) {
+ return
+ }
+ openSidePanel(SidePanelTab.Max, autoRunMaxPrompt(queryScan.assistantPrompt))
+ }
- return <QueryScanBanner queryScan={queryScan} />
+ return <QueryScanBanner queryScan={queryScan} onFixWithAI={askAssistant} />
}
diff --git a/posthog/query_scan/explain.py b/posthog/query_scan/explain.py
index 130e06496454..018156dad7e4 100644
--- a/posthog/query_scan/explain.py
+++ b/posthog/query_scan/explain.py
@@ -13,7 +13,7 @@ from posthog.dataclasses import frozen
# Spelled out rather than imported, so this parser does not pull in the model layer.
_EVENTS_TABLE_NAMES = ("events", "events_json", "sharded_events", "sharded_events_json")
-_PERSON_TABLE_NAMES = ("person", "person_distinct_id2", "person_distinct_id_overrides")
+_PERSON_TABLE_NAMES = ("person",)
_MIN_MAX_TYPE = "Min-Max"
_PRIMARY_KEY_TYPE = "PrimaryKey"
diff --git a/posthog/query_scan/test/test_explain.py b/posthog/query_scan/test/test_explain.py
index 1f3ad6638229..8d23ab92824a 100644
--- a/posthog/query_scan/test/test_explain.py
+++ b/posthog/query_scan/test/test_explain.py
@@ -179,7 +179,8 @@ class TestExplainParsing(SimpleTestCase):
("the native-JSON table", "posthog.sharded_events_json", True, False),
("another table whose name ends in events", "posthog.ai_events", False, False),
("the persons table", "posthog.person", False, True),
- ("a person override table", "posthog.person_distinct_id_overrides", False, True),
+ ("a person override table", "posthog.person_distinct_id_overrides", False, False),
+ ("the person distinct ID table", "posthog.person_distinct_id2", False, False),
]
)
def test_table_names_are_classified_by_the_description(