fix(sqllab): quote autocomplete table names that need it#41199
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41199 +/- ##
=======================================
Coverage 64.34% 64.34%
=======================================
Files 2653 2653
Lines 144963 144968 +5
Branches 33452 33454 +2
=======================================
+ Hits 93281 93286 +5
Misses 49997 49997
Partials 1685 1685
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review Agent Run #f1a006Actionable 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 |
SQL Lab autocomplete inserted table names verbatim, so picking a name with spaces or other non-identifier characters (e.g. "COVID Vaccines") produced invalid SQL. Quote the inserted value with double quotes (and double any embedded quotes) when the name isn't a simple identifier; simple names are still inserted as-is. The display label is unchanged.
8c307be to
0522ac1
Compare
| allCachedTables.map(({ value, label, schema: tableSchema }) => ({ | ||
| name: label, | ||
| value, | ||
| value: quoteIdentifier(value), |
There was a problem hiding this comment.
Suggestion: Using the quoted identifier as the table completion value breaks downstream table metadata flows because this value is also passed to addTable on selection. That stores names like "COVID Vaccines" (with quotes) in pinned table state, and later metadata requests use that quoted string as the name query param, which can fail table lookups that expect the raw table name. Keep autocomplete insertion quoting separate from the canonical table identity used by state/API calls. [api mismatch]
Severity Level: Critical 🚨
- ❌ SQL Lab table preview fails for quoted-name tables.
- ❌ Table metadata panel shows missing columns for those tables.
- ⚠️ Column autocomplete misses columns from pinned quoted tables.Steps of Reproduction ✅
1. Open SQL Lab editor, which renders `EditorWrapper` at
`superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx:104-120` and passes
`keywords={keywords}` from `useKeywords(...)` at lines 26-35 and 382.
2. `useKeywords` builds `tableKeywords` in
`superset-frontend/src/SqlLab/components/EditorWrapper/useKeywords.ts:204-210`, setting
each table keyword to `{ name: label, value: quoteIdentifier(value), schema: tableSchema,
meta: 'table', completer: { insertMatch } }`, so a table like `COVID Vaccines` produces
`value: "\"COVID Vaccines\""`.
3. In the editor, trigger autocomplete and select the `COVID Vaccines` table completion;
Ace calls `insertMatch` defined in `useKeywords.ts:165-187`, which for `data.meta ===
'table'` dispatches `addTable(..., data.value, catalog ?? null, data.schema ?? schema ??
'', false)` using the quoted `data.value` (`"COVID Vaccines"`) as the `tableName`.
4. `addTable` in `superset-frontend/src/SqlLab/actions/sqlLab.ts:22-37` stores this quoted
`tableName` as `table.name`, and later `SouthPane` at
`superset-frontend/src/SqlLab/components/SouthPane/index.tsx:82-103` passes
`tableName={name}` into `TablePreview`, which uses `tableName` as the `table` parameter to
`useTableMetadataQuery` (`TablePreview/index.tsx:136-143`), leading `tables.ts:14-19` to
call `/api/v1/database/{dbId}/table_metadata/?name="%22COVID%20Vaccines%22"&schema=...`;
because the backend expects the raw table name (`COVID Vaccines`) without quotes, metadata
lookups and previews for tables pinned via autocomplete can fail.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/src/SqlLab/components/EditorWrapper/useKeywords.ts
**Line:** 208:208
**Comment:**
*Api Mismatch: Using the quoted identifier as the table completion `value` breaks downstream table metadata flows because this `value` is also passed to `addTable` on selection. That stores names like `"COVID Vaccines"` (with quotes) in pinned table state, and later metadata requests use that quoted string as the `name` query param, which can fail table lookups that expect the raw table name. Keep autocomplete insertion quoting separate from the canonical table identity used by state/API calls.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
This does not apply on the Ace editor path. toAceKeyword in AceEditorProvider.tsx copies only name/value/score/meta/docText/docHTML and drops completer, so insertMatch never runs and addTable is not called on selection. Ace inserts value directly, which is why the fix quotes value. No quoted name reaches table state or the metadata API through this path. The addTable side effect on select is already inactive for the same reason, independent of this change.
There was a problem hiding this comment.
✅ Customized review instruction saved!
Instruction:
Do not flag quoted table completion values in the Ace editor path when
toAceKeywordstripscompleter; in that flowinsertMatchdoes not run, so autocomplete insertion does not calladdTableor store quoted names in table state/API calls.
Applied to:
superset-frontend/src/SqlLab/components/AceEditorProvider.tsxsuperset-frontend/src/SqlLab/components/EditorWrapper/**
💡 To manage or update this instruction, visit: CodeAnt AI Settings
|
The flagged issue is correct. The current implementation uses the quoted identifier as the To resolve this, you should separate the value used for editor insertion (which requires quoting) from the value used for state/API identification (which should be the raw name). You can update the Would you like me to fetch all other comments on this PR to validate and implement fixes for them as well? superset-frontend/src/SqlLab/components/EditorWrapper/useKeywords.ts |
|
Bito Automatic Review Failed - Technical Failure |
SUMMARY
SQL Lab autocomplete inserted table names exactly as stored. When a name isn't a simple identifier (it contains spaces or punctuation, or starts with a digit), inserting it verbatim produces invalid SQL. Picking a table like
COVID Vaccinesfrom the dropdown gaveSELECT * FROM COVID Vaccines, which fails to parse.This quotes the inserted value with double quotes when the name isn't a simple identifier, doubling any embedded quotes so names containing
"stay valid. Simple identifiers are still inserted as-is, and the human-readable label shown in the dropdown is unchanged.Quoting uses ANSI double-quote identifiers. Dialect-specific quote characters (e.g. backticks on MySQL) would be a reasonable follow-up.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE:

AFTER:

TESTING INSTRUCTIONS
COVID Vaccines).FROM COVID Vaccines) and the query fails to parse.FROM "COVID Vaccines") and runs.simple_table) is still inserted without quotes.ADDITIONAL INFORMATION