codeant-ai-for-open-source[bot] commented on code in PR #41019:
URL: https://github.com/apache/superset/pull/41019#discussion_r3491334325
##########
superset-frontend/src/SqlLab/actions/sqlLab.ts:
##########
@@ -996,7 +998,22 @@ export function removeQuery(query: Query):
SqlLabThunkAction<Promise<unknown>> {
: Promise.resolve();
return sync
- .then(() => dispatch({ type: REMOVE_QUERY, query }))
+ .then(() => {
+ dispatch({ type: REMOVE_QUERY, query });
+ dispatch(
+ queryHistoryApi.util.updateQueryData(
+ 'editorQueries',
+ { editorId: queryEditorId },
+ draft => {
+ const index = draft.result.findIndex(({ id }) => id ===
query.id);
+ if (index !== -1) {
+ draft.result.splice(index, 1);
+ draft.count = Math.max(0, draft.count - 1);
Review Comment:
**Suggestion:** This removes only the first matching item, so if the cache
already contains duplicate entries for the same query id (possible with the
current infinite-scroll merge behavior), at least one duplicate remains visible
after deletion. Remove all matching entries for the deleted id instead of only
the first match. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Duplicate query rows persist after delete in history.
- ⚠️ Users see “deleted” queries still listed.
- ⚠️ Cached count mismatches actual unique queries.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. The `editorQueries` RTK Query endpoint in
`superset-frontend/src/hooks/apiResources/queries.ts:110-173` defines a
`merge` function
that appends each new page’s `result` entries into `currentCache.result`
(`queries.ts:170-172`) without deduplication; the test `merges paginated
results` in
`queries.test.ts:120-167` explicitly exercises this by loading two pages for
the same
editor and expecting `result` to contain the same mapped query twice.
2. QueryHistory at
`superset-frontend/src/SqlLab/components/QueryHistory/index.tsx:26-42`
constructs the `editorQueries` list passed into `QueryTable` by
concatenating Redux
`sqlLab.queries` with `data.result` from `editorQueries`, so any duplicate
entries with
the same `id` (client_id) in `data.result` appear as multiple identical rows
in the
history table.
3. With such duplicated entries present, the user clicks the delete icon on
one of those
rows; QueryTable’s actions column at
`components/QueryTable/index.tsx:147-175` binds the
delete tooltip’s `onClick` to `dispatch(removeQuery(query))`, invoking the
`removeQuery`
thunk in `superset-frontend/src/SqlLab/actions/sqlLab.ts:30-67`.
4. In the success handler of `removeQuery`, the cache update block at
`actions/sqlLab.ts:41-53` executes `const index = draft.result.findIndex(({
id }) => id
=== query.id);` and, if an index is found, splices only that single entry
from
`draft.result` and decrements `draft.count`; any additional entries whose
`id` matches
`query.id` remain in `draft.result`, so after the thunk completes,
QueryHistory continues
to render at least one row for the supposedly deleted query, leaving
duplicates partially
deleted and the query still visible in the history.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=87a664411d46486ebc644e653511240b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=87a664411d46486ebc644e653511240b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(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/actions/sqlLab.ts
**Line:** 1008:1011
**Comment:**
*Logic Error: This removes only the first matching item, so if the
cache already contains duplicate entries for the same query id (possible with
the current infinite-scroll merge behavior), at least one duplicate remains
visible after deletion. Remove all matching entries for the deleted id instead
of only the first match.
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%2F41019&comment_hash=bf9399438039276792ae838ade7e3840e0dde56c64665bdadc253d6d100517a8&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41019&comment_hash=bf9399438039276792ae838ade7e3840e0dde56c64665bdadc253d6d100517a8&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]