Skip to content

Commit c93810f

Browse files
sadpandajoeclaude
andcommitted
fix(explore): send database backend as string in View Query format request
The View Query modal's SQL formatting toggle was returning a 400 Bad Request error because the engine parameter was being sent as an object instead of a string to the format_sql endpoint. When the backend needs to be fetched from the dataset API, the code was assigning the entire database object {backend: "postgresql"} rather than extracting just the backend property string. Changes: - Use object destructuring to extract backend string from database object - Add comprehensive test validating complete API payload structure - Test verifies engine is sent as string, not object Fixes #35682 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a5eb02d commit c93810f

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

superset-frontend/src/explore/components/controls/ViewQuery.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,29 @@ test('uses exploreBackend from Redux state when available', async () => {
265265
expect(formatCallBody.engine).toBe('postgresql');
266266
expect(fetchMock.calls(datasetApiEndpoint)).toHaveLength(0);
267267
});
268+
269+
test('sends engine as string (not object) when fetched from dataset API', async () => {
270+
const stateWithoutBackend = {
271+
...mockState(),
272+
explore: undefined,
273+
};
274+
275+
setup(mockProps, stateWithoutBackend);
276+
277+
await waitFor(() => {
278+
expect(fetchMock.calls(datasetApiEndpoint)).toHaveLength(1);
279+
});
280+
281+
await waitFor(() => {
282+
expect(fetchMock.calls(formatSqlEndpoint)).toHaveLength(1);
283+
});
284+
285+
const formatCallBody = JSON.parse(
286+
fetchMock.lastCall(formatSqlEndpoint)?.[1]?.body as string,
287+
);
288+
289+
expect(formatCallBody).toEqual({
290+
sql: mockProps.sql,
291+
engine: 'sqlite',
292+
});
293+
});

superset-frontend/src/explore/components/controls/ViewQuery.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ const ViewQuery: FC<ViewQueryProps> = props => {
106106
const response = await SupersetClient.get({
107107
endpoint: `/api/v1/dataset/${datasetId}?q=${queryParams}`,
108108
});
109-
backend = response.json.result.database;
109+
const { backend: datasetBackend } = response.json.result.database;
110+
backend = datasetBackend;
110111
}
111112

112113
// Format the SQL query

0 commit comments

Comments
 (0)