: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(sql-editor): prevent crash when query URL param is non-string (#62376)
Xander10f2000b1323
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.tsindex 87f0caccce5f..3bc65844c334 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts@@ -1018,6 +1018,25 @@ describe('sqlEditorLogic', () => {expect(router.values.hashParams.q).toEqual('SELECT 1')expect(router.values.hashParams.output_tab).toEqual(OutputTab.Both)})++ it('coerces a numeric query hash param to a string instead of crashing splitQueryRanges', async () => {+ logic = sqlEditorLogic({+ tabId: TAB_ID,+ monaco: createMockMonaco(),+ editor: createMockEditor(),+ })+ logic.mount()++ // kea-router decodes `q=42` back to the number 42, which used to reach queryInput unchanged+ router.actions.push(urls.sqlEditor(), undefined, { q: 42 })++ await expectLogic(logic).toDispatchActions(['createTab', 'updateTab'])++ expect(logic.values.queryInput).toEqual('42')+ // Reading splitQueryRanges threw "e.trim is not a function" when queryInput was the number 42+ expect(() => logic.values.splitQueryRanges).not.toThrow()+ expect(logic.values.splitQueryRanges).toHaveLength(1)+ })})describe('source URL parameter', () => {diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsxindex 27911d462bb3..07654eed1a14 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx@@ -2355,8 +2355,8 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([tabAdded = truerouter.actions.replace(urls.sqlEditor(), undefined, getTabHash(values))} else if (searchParams.open_query) {- // Open query string- actions.createTab(searchParams.open_query)+ // kea-router decodes numeric/JSON-shaped URL values to non-strings; coerce so queryInput stays a string+ actions.createTab(String(searchParams.open_query))tabAdded = true} else if (hashParams.q &&@@ -2365,9 +2365,10 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([!insightShortIdFromUrl &&(values.queryInput === null ||!activeTabMatchesUrlTarget(values.activeTab, {}) ||- values.queryInput !== hashParams.q)+ values.queryInput !== String(hashParams.q))) {- actions.createTab(hashParams.q)+ // kea-router decodes numeric/JSON-shaped URL values to non-strings; coerce so queryInput stays a string+ actions.createTab(String(hashParams.q))tabAdded = true} else if (values.queryInput === null) {actions.createTab('')