sadpandajoe opened a new pull request, #35898: URL: https://github.com/apache/superset/pull/35898
<!--- Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/ Example: fix(dashboard): load charts correctly --> ### SUMMARY <!--- Describe the change below, including rationale and design decisions --> Fixes the SQL formatting toggle in the View Query modal which was returning a 400 Bad Request error. **The Problem:** When users clicked the format toggle in the View Query modal, the request to `/api/v1/sqllab/format_sql/` was sending the `engine` parameter as an object `{backend: "postgresql"}` instead of a string `"postgresql"`. The backend schema expects a string, causing validation to fail with `"Not a valid string."` error. **Root Cause:** When the backend engine is not available in Redux state, the code fetches it from the dataset API. The bug occurred during this extraction - the entire database object was being assigned instead of extracting just the `backend` property string. **The Fix:** - Use object destructuring to properly extract the backend string: `const { backend: datasetBackend } = response.json.result.database;` - Added comprehensive test to validate the complete API payload structure (both `sql` and `engine` fields) - Test ensures `engine` is sent as a string, not an object, preventing regression ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <!--- Skip this if not applicable --> ### TESTING INSTRUCTIONS <!--- Required! What steps can be taken to manually verify the changes? --> **Automated Testing:** ```bash npm run test -- ViewQuery.test.tsx All 12 tests should pass, including the new test: 'sends engine as string (not object) when fetched from dataset API' ``` Manual Testing (Optional): 1. Open SQL Lab or Explore view 2. Write a SQL query (e.g., SELECT * FROM table) 3. Click "View Query" button to open the modal 4. Click the format toggle switch 5. Verify: SQL is formatted successfully without errors 6. Toggle back to original - should work without errors ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] Has associated issue: Fixes #35682 - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [ ] Introduces new feature or API - [ ] Removes existing feature or API -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
