Skip to content

fix(api,sql): use json_response in Api.query and log dialect fallback#40644

Merged
rusackas merged 1 commit into
masterfrom
fix/api-json-response-and-parse-fallback-log
Jun 2, 2026
Merged

fix(api,sql): use json_response in Api.query and log dialect fallback#40644
rusackas merged 1 commit into
masterfrom
fix/api-json-response-and-parse-fallback-log

Conversation

@rusackas
Copy link
Copy Markdown
Member

@rusackas rusackas commented Jun 2, 2026

SUMMARY

Two small, low-risk correctness/consistency fixes:

  1. Consistent Content-Type in Api.query (superset/views/api.py): the Api.query() endpoint returned a raw json.dumps(...) string, unlike its sibling handlers query_form_data and time_range, which use self.json_response(...). Returning a bare string leaves the response Content-Type defaulting to text/html rather than application/json. Switched it to return self.json_response(payload_json). json_response uses the same json_int_dttm_ser default serializer and ignore_nan=True, so the response body is equivalent — only the Content-Type header is now set consistently.

  2. Observable SQL dialect fallback (superset/sql/parse.py): when parsing with the base dialect fails and the script contains backticks, the parser silently falls back to the MySQL dialect (to support backtick-quoted identifiers). Added a logger.warning on that branch so the fallback is observable. Parsing behavior is unchanged; only a log line is added (module logger already existed).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (backend-only change).

TESTING INSTRUCTIONS

  • python -m pytest tests/unit_tests/views/test_base.py tests/unit_tests/sql/parse_tests.py -q (549 passed locally).
  • New test_api_query_returns_json_content_type asserts the Api.query response has an application/json content type.
  • New test_backtick_fallback_logs_warning asserts a warning is logged when the MySQL dialect fallback path is taken.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

🤖 Generated with Claude Code

Make Api.query return self.json_response(...) like its query_form_data
and time_range siblings so the Content-Type header is set consistently
instead of returning a raw JSON string. The payload and serializer
behavior are unchanged (json_response uses the same json_int_dttm_ser
default and ignore_nan).

Also add a logger.warning when SQL parsing falls back from the base
dialect to the MySQL dialect (triggered by backtick-quoted identifiers),
so the fallback is observable. Parsing behavior is unchanged.

Adds unit tests for both: the JSON content type of the Api.query
response and the warning log emitted on the MySQL dialect fallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rusackas rusackas requested review from dpgaspar and hainenber June 2, 2026 00:13
@dosubot dosubot Bot added api Related to the REST API logging Creates a UI or API endpoint that could benefit from logging. labels Jun 2, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 2, 2026

Code Review Agent Run #6fdee2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: b2a2e2e..b2a2e2e
    • superset/sql/parse.py
    • superset/views/api.py
    • tests/unit_tests/sql/parse_tests.py
    • tests/unit_tests/views/test_base.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 2, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit b2a2e2e
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a1e2038c6b1a00008c48d94
😎 Deploy Preview https://deploy-preview-40644--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.94%. Comparing base (2b8e31b) to head (b2a2e2e).
⚠️ Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
superset/sql/parse.py 0.00% 1 Missing ⚠️
superset/views/api.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40644      +/-   ##
==========================================
- Coverage   63.94%   63.94%   -0.01%     
==========================================
  Files        2658     2658              
  Lines      143011   143012       +1     
  Branches    32866    32866              
==========================================
  Hits        91454    91454              
- Misses      49994    49995       +1     
  Partials     1563     1563              
Flag Coverage Δ
hive 39.75% <0.00%> (-0.01%) ⬇️
mysql 58.40% <0.00%> (-0.01%) ⬇️
postgres 58.47% <0.00%> (-0.01%) ⬇️
presto 41.36% <0.00%> (-0.01%) ⬇️
python 59.96% <0.00%> (-0.01%) ⬇️
sqlite 58.13% <0.00%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Two small backend correctness/consistency fixes: ensure Api.query sets a JSON Content-Type header by using self.json_response, and add a warning log when the SQL parser silently falls back from the base to the MySQL dialect for backtick-containing scripts.

Changes:

  • superset/views/api.py: replace raw json.dumps(...) return with self.json_response(payload_json) for consistent Content-Type.
  • superset/sql/parse.py: emit a logger.warning when falling back to MySQL dialect on backtick-containing scripts.
  • Added unit tests for both behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
superset/views/api.py Use json_response so Api.query sets application/json Content-Type.
superset/sql/parse.py Log a warning on MySQL dialect fallback to make it observable.
tests/unit_tests/views/test_base.py New test asserting Api.query returns application/json.
tests/unit_tests/sql/parse_tests.py New test asserting the dialect fallback emits a warning log.

@sha174n sha174n added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Jun 2, 2026
@rusackas rusackas merged commit b97d3ef into master Jun 2, 2026
66 checks passed
@rusackas rusackas deleted the fix/api-json-response-and-parse-fallback-log branch June 2, 2026 18:48
@github-project-automation github-project-automation Bot moved this from Needs Review to Approved and/or Merged in Superset Review Help Wanted Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API logging Creates a UI or API endpoint that could benefit from logging. merge-if-green If approved and tests are green, please go ahead and merge it for me size/M

Projects

Status: Approved and/or Merged

Development

Successfully merging this pull request may close these issues.

4 participants