fix(SqlLab): enhance SQL formatting with Jinja template support.#36277
Conversation
Code Review Agent Run #e66591Actionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
| const { sql } = getUpToDateQuery(getState(), queryEditor); | ||
| const qe = getUpToDateQuery(getState(), queryEditor); | ||
| const { sql, dbId, templateParams } = qe; | ||
| const body = { sql }; |
There was a problem hiding this comment.
Can we still do this inline? are we using the variable qe anywhere else?
There was a problem hiding this comment.
Of course, and you're right, there are no more uses of the var qe.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #36277 +/- ##
==========================================
+ Coverage 60.48% 67.99% +7.50%
==========================================
Files 1931 636 -1295
Lines 76236 46832 -29404
Branches 8568 5084 -3484
==========================================
- Hits 46114 31842 -14272
+ Misses 28017 13712 -14305
+ Partials 2105 1278 -827
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ng state values, removing solved TODO.
|
@geido This workflow is deprecated! Please use the new Superset Showtime system instead:
Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@geido Ephemeral environment spinning up at http://44.249.161.7:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
) (cherry picked from commit e7c0604)
…che#36277) (cherry picked from commit e7c0604)
- theming.mdx: document brandAppName theme token (PR #37370) — controls app name in browser title/nav/emails, takes precedence over APP_NAME config - cache.mdx: document SUPERSET_CACHE_WARMUP_USER config key (PR #38449) — controls the user account Selenium WebDriver authenticates as for thumbnail rendering and cache warmup; update selenium → Selenium capitalization - security.mdx: document missing SQL Lab RBAC permissions (PR #36263) — can_estimate_query_cost and can_format_sql must be explicitly granted - sql-templating.mdx: document Jinja support in calculated columns (PR #37791) with examples; add tip that "Format SQL" is Jinja-aware and dialect-specific (PRs #36277, #39393) - creating-your-first-dashboard.mdx: document dashboard tab URLs (#38660), auto-refresh (#37459), "Last queried at" timestamp (#36934), and tab selection when saving charts to dashboards (#36332) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- theming.mdx: document brandAppName theme token (PR #37370) — controls app name in browser title/nav/emails, takes precedence over APP_NAME config - cache.mdx: document SUPERSET_CACHE_WARMUP_USER config key (PR #38449) — controls the user account Selenium WebDriver authenticates as for thumbnail rendering and cache warmup; update selenium → Selenium capitalization - security.mdx: document missing SQL Lab RBAC permissions (PR #36263) — can_estimate_query_cost and can_format_sql must be explicitly granted - sql-templating.mdx: document Jinja support in calculated columns (PR #37791) with examples; add tip that "Format SQL" is Jinja-aware and dialect-specific (PRs #36277, #39393) - creating-your-first-dashboard.mdx: document dashboard tab URLs (#38660), auto-refresh (#37459), "Last queried at" timestamp (#36934), and tab selection when saving charts to dashboards (#36332) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SUMMARY
Enable Jinja-aware SQL formatting by passing database_id/template_params from the UI and processing templates server-side before formatting.
This is used on the experimental Parameters feature of the SQL Labs.
Details
Backend:
POST /api/v1/sqllab/format_sql/now acceptsdatabase_idandtemplate_params(JSON string) viaFormatQueryPayloadSchema.get_template_processor) before runningSQLScript.format.Frontend (SQL Lab):
formatQueryincludesdatabase_idandtemplate_params(stringified when needed) from the up-to-date query editor state in the request body.Tests:
formatQuerypayload construction and dispatch behavior.format_sqlresponse.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
93622-error-jinja-formatting-sql-formatting.mov
After
93622-jinja-formatting-sql-formatting.mov
TESTING INSTRUCTIONS
examplesDB is selected.{"tbl": "\"Vehicle Sales\""}as the parameter value.select * from {{tbl}}and validate the query works.ADDITIONAL INFORMATION
ENABLE_TEMPLATE_PROCESSING