You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/10/30 01:25:21 UTC
(superset) branch issue-35682-fix-view-query-format created (now c93810f80c)
This is an automated email from the ASF dual-hosted git repository.
jli pushed a change to branch issue-35682-fix-view-query-format
in repository https://gitbox.apache.org/repos/asf/superset.git
at c93810f80c fix(explore): send database backend as string in View Query format request
This branch includes the following new commits:
new c93810f80c fix(explore): send database backend as string in View Query format request
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix(explore): send database backend as string in View Query format request
Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jli pushed a commit to branch issue-35682-fix-view-query-format
in repository https://gitbox.apache.org/repos/asf/superset.git
commit c93810f80caeeca78bf69e3b43f32e0164972e87
Author: Joe Li <jo...@preset.io>
AuthorDate: Wed Oct 29 18:23:47 2025 -0700
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 <no...@anthropic.com>
---
.../explore/components/controls/ViewQuery.test.tsx | 26 ++++++++++++++++++++++
.../src/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 1340c1af10..dbce360a17 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 ed9cd7d9de..0d2dc7b685 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<ViewQueryProps> = 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