From be3690c22be743e8fbc0cf609feff285181dddb2 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Fri, 31 Oct 2025 11:09:51 -0700 Subject: [PATCH] fix(explore): formatting the SQL in "View Query" pop-up doesn't format (#35898) Co-authored-by: Claude --- .../components/controls/ViewQuery.test.tsx | 26 +++++++++++++++++++ .../explore/components/controls/ViewQuery.tsx | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx b/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx index 1340c1af109..dbce360a173 100644 --- a/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx +++ b/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx @@ -265,3 +265,29 @@ test('uses exploreBackend from Redux state when available', async () => { expect(formatCallBody.engine).toBe('postgresql'); expect(fetchMock.calls(datasetApiEndpoint)).toHaveLength(0); }); + +test('sends engine as string (not object) when fetched from dataset API', async () => { + const stateWithoutBackend = { + ...mockState(), + explore: undefined, + }; + + setup(mockProps, stateWithoutBackend); + + await waitFor(() => { + expect(fetchMock.calls(datasetApiEndpoint)).toHaveLength(1); + }); + + await waitFor(() => { + expect(fetchMock.calls(formatSqlEndpoint)).toHaveLength(1); + }); + + const formatCallBody = JSON.parse( + fetchMock.lastCall(formatSqlEndpoint)?.[1]?.body as string, + ); + + expect(formatCallBody).toEqual({ + sql: mockProps.sql, + engine: 'sqlite', + }); +}); diff --git a/superset-frontend/src/explore/components/controls/ViewQuery.tsx b/superset-frontend/src/explore/components/controls/ViewQuery.tsx index ed9cd7d9de4..0d2dc7b685d 100644 --- a/superset-frontend/src/explore/components/controls/ViewQuery.tsx +++ b/superset-frontend/src/explore/components/controls/ViewQuery.tsx @@ -106,7 +106,8 @@ const ViewQuery: FC = props => { const response = await SupersetClient.get({ endpoint: `/api/v1/dataset/${datasetId}?q=${queryParams}`, }); - backend = response.json.result.database; + const { backend: datasetBackend } = response.json.result.database; + backend = datasetBackend; } // Format the SQL query