codeant-ai-for-open-source[bot] commented on code in PR #40037:
URL: https://github.com/apache/superset/pull/40037#discussion_r3221702393
##########
superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx:
##########
@@ -55,8 +56,12 @@ const ExploreCtasResultsButton = ({
};
const visualize = () => {
- dispatch(createCtasDatasource(buildVizOptions))
- .then((data: { table_id: number }) => {
+ (
+ dispatch(createCtasDatasource(buildVizOptions)) as unknown as Promise<{
+ table_id: number;
+ }>
Review Comment:
**Suggestion:** The new double type assertion forces
`dispatch(createCtasDatasource(...))` to a custom promise shape and bypasses
the real thunk return contract, which hides API/schema mismatches from
TypeScript. This can silently produce `undefined` datasource IDs at runtime if
the returned payload shape differs (for example `{ id }`), so remove the `as
unknown as ...` cast and align the thunk/action return type with the actual
response shape instead. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ SqlLab CTAS flow stores malformed datasource string in state.
- ⚠️ Thunk return type mismatches actual `/dataset/get_or_create/` schema.
- ⚠️ Double cast hides API/schema drift from TypeScript checks.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Execute a CTAS query in SQL Lab so that a temporary table is created and
the
`ResultSet` component renders the CTAS alert with actions, including
`<ExploreCtasResultsButton />` (see
`superset-frontend/src/SqlLab/components/ResultSet/index.tsx:19-23` in the
alert block).
2. Click the "Explore" button, which calls the `visualize` handler in
`ExploreCtasResultsButton` at
`superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx:58-83`.
This
invokes `dispatch(createCtasDatasource(buildVizOptions))` and immediately
forces its
return type to `Promise<{ table_id: number }>` via the double assertion
shown at lines
59-62.
3. The thunk `createCtasDatasource` in
`superset-frontend/src/SqlLab/actions/sqlLab.ts:69-77` is declared as
`SqlLabThunkAction<Promise<{ id: number }>>` but actually calls
`/api/v1/dataset/get_or_create/` and returns `json.result`. The OpenAPI
schema for this
endpoint in `docs/static/resources/openapi.json:23870-23928` defines
`result` as `{
"table_id": integer }`, so the declared thunk return type (`{ id: number }`)
does not
match the real payload shape (`{ table_id: number }`).
4. Because the UI code at `index.tsx:59-62` uses `as unknown as Promise<{
table_id: number
}>` instead of the thunk's declared return type, TypeScript cannot surface
this mismatch:
the component compiles while expecting `table_id`, the thunk is annotated as
returning `{
id }`, and the API returns `{ table_id }`. The same mismatch also affects
`createDatasourceSuccess` in
`superset-frontend/src/SqlLab/actions/sqlLab.ts:11-13`, which
is typed as receiving `{ id: number }` but is called with `json.result` (a
`{ table_id }`
object) for CTAS, causing `data.id` to be `undefined` and the `datasource`
string in the
`CREATE_DATASOURCE_SUCCESS` action to become `'undefined__table'`. Removing
the double
assertion and aligning the thunk/action types with the actual `{ table_id }`
response
would let TypeScript catch and prevent this contract break.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2FSqlLab%2Fcomponents%2FExploreCtasResultsButton%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%2059%3A62%0A%2A%2AComment%3A%2A%2A%0A%09%2AApi%20Mismatch%3A%20The%20new%20double%20type%20assertion%20forces%20%60dispatch%28createCtasDatasource%28...%29%29%60%20to%20a%20custom%20promise%20shape%20and%20bypasses%20the%20real%20thunk%20return%20contract%2C%20which%20hides%20API%2Fschema%20mismatches%20from%20TypeScript.%20This%20can%20silently%20produce%20%60undefined%60%20datasource%20IDs%20at%20runtime%20if%20the%20returned%20payload%20shape%20differs%20%28for%20example%20%60%7B%20id%20%7D%60%29%2C%20so%20remove%20the%20%60as%20unknown%20as%20...%60%20cast%20and%20align%20the%20thunk%2Faction%20return%20type%20with%20the%20actual%20response%20shape%20instead.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20is
sue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2FSqlLab%2Fcomponents%2FExploreCtasResultsButton%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%2059%3A62%0A%2A%2AComment%3A%2A%2A%0A%09%2AApi%20Mismatch%3A%20The%20new%20double%20type%20assertion%20forces%20%60dispatch%28createCtasDatasource%28...%29%29%60%20to%20a%20custom%20promise%20shape%20and%20bypasses%20the%20real%20thunk%20
return%20contract%2C%20which%20hides%20API%2Fschema%20mismatches%20from%20TypeScript.%20This%20can%20silently%20produce%20%60undefined%60%20datasource%20IDs%20at%20runtime%20if%20the%20returned%20payload%20shape%20differs%20%28for%20example%20%60%7B%20id%20%7D%60%29%2C%20so%20remove%20the%20%60as%20unknown%20as%20...%60%20cast%20and%20align%20the%20thunk%2Faction%20return%20type%20with%20the%20actual%20response%20shape%20instead.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx
**Line:** 59:62
**Comment:**
*Api Mismatch: The new double type assertion forces
`dispatch(createCtasDatasource(...))` to a custom promise shape and bypasses
the real thunk return contract, which hides API/schema mismatches from
TypeScript. This can silently produce `undefined` datasource IDs at runtime if
the returned payload shape differs (for example `{ id }`), so remove the `as
unknown as ...` cast and align the thunk/action return type with the actual
response shape instead.
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 fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40037&comment_hash=3f44fd89f29657a8cac61a1ca7b925f36bb2e2d3931876c10778c4e9c7ea011e&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40037&comment_hash=3f44fd89f29657a8cac61a1ca7b925f36bb2e2d3931876c10778c4e9c7ea011e&reaction=dislike'>👎</a>
--
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]