fix(sql): quote identifiers in transpile_to_dialect to fix case-sensitive column filters#39521
fix(sql): quote identifiers in transpile_to_dialect to fix case-sensitive column filters#39521alexandrusoare wants to merge 4 commits intomasterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39521 +/- ##
==========================================
- Coverage 64.57% 64.53% -0.05%
==========================================
Files 2561 2561
Lines 133470 133386 -84
Branches 31015 30976 -39
==========================================
- Hits 86182 86074 -108
- Misses 45796 45820 +24
Partials 1492 1492
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:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #70db5dActionable Suggestions - 0Review 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 |
| if needs_transpilation: | ||
| clause = transpile_to_dialect(clause, engine) | ||
| clause = transpile_to_dialect( | ||
| clause, engine, source_engine=engine, identify=True |
There was a problem hiding this comment.
This calls transpile_to_dialect with source and target as the same engine? Maybe a comment on why this is necessary
|
The call to |
| if sanitized_clause != clause: | ||
| self.extras[param] = sanitized_clause | ||
| self.extras[param] = sanitized_clause |
There was a problem hiding this comment.
Do we need a test here to prevent a regression?
Code Review Agent Run #f63db8Actionable Suggestions - 0Review 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 |
SUMMARY
"STATE") failing withcolumn "state" does not existon Postgres and other databasesidentify=Truetotranspile_to_dialect()so SQLGlot emits dialect-correct identifier quoting_sanitize_filters()always writing back the sanitized clause (was conditionally skipped, causing transpiled results to be lost)Issue
When a chart has a SQL filter referencing a case-sensitive column (e.g.
STATE ILIKE '%AL%'), the query fails on Postgres with:This affects any database that folds unquoted identifiers to lowercase (Postgres, Redshift, etc.) when columns were created with quoted-uppercase names (e.g.
CREATE TABLE t ("STATE" TEXT)).Root cause
Two bugs compounding each other:
transpile_to_dialect()did not quote identifiers. It called SQLGlot'sgenerate()withoutidentify=True, so identifiers likeSTATEwere re-emitted unquoted — even for dialects where that causes case-folding._sanitize_filters()conditionally wrote back toself.extras. The code only updatedself.extras[param]whensanitized_clause != clause. But aftertranspile_to_dialect()modifies the localclausevariable (adding quotes),sanitize_clause()produces the same result — so the condition wasFalseand the original unquoted value inself.extraswas never replaced.Fix
identify=Trueto thegenerate()call intranspile_to_dialect()— makes SQLGlot emit dialect-correct quoting ("STATE"for Postgres,STATEfor BigQuery/MySQL,[STATE]for MSSQL)self.extras[param] = sanitized_clausein_sanitize_filters()— removes the stale conditional that prevented transpiled results from being persistedBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE
Screen.Recording.2026-04-22.at.12.04.32.mov
AFTER
Screen.Recording.2026-04-22.at.12.01.19.mov
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION