codeant-ai-for-open-source[bot] commented on code in PR #39894:
URL: https://github.com/apache/superset/pull/39894#discussion_r3475256909
##########
superset-frontend/src/dashboard/actions/datasources.ts:
##########
@@ -61,8 +63,21 @@ export function fetchDatasourceMetadata(key: string) {
return dispatch(setDatasource(datasource, key));
}
+ if (inFlightDatasourceKeys.has(key)) {
+ return undefined;
Review Comment:
**Suggestion:** Returning `undefined` for duplicate in-flight requests
breaks the thunk contract for callers that await this action. Any concurrent
caller (for example code using `Promise.all` with
`dispatch(fetchDatasourceMetadata(...))`) will proceed immediately instead of
waiting for metadata, and it also cannot observe a rejection if the original
request fails. Keep a per-key in-flight promise map and return the same promise
to all callers so completion/error is propagated consistently. [race condition]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ addSliceToDashboard may not await datasource metadata.
- ⚠️ Callers cannot observe failures from original metadata request.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Observe the thunk implementation in
`superset-frontend/src/dashboard/actions/datasources.ts` lines 57–70:
`fetchDatasourceMetadata(key)` returns either a cached datasource, a
`SupersetClient.get(...).then(...)` promise, or `undefined` when
`inFlightDatasourceKeys`
contains `key` (guard at lines 66–67).
2. Confirm that callers treat this thunk as promise-returning:
`superset-frontend/src/dashboard/actions/datasources.test.ts` lines 65–69
`await
fetchDatasourceMetadata(KEY)(dispatch, buildGetState());` and lines 27–29
`await
expect(fetchDatasourceMetadata(KEY)(dispatch,
getState)).rejects.toThrow('boom');` both
rely on the inner function returning a promise that resolves or rejects.
3. Inspect `superset-frontend/src/dashboard/actions/dashboardState.ts` lines
918–929 where
`addSliceToDashboard` is defined to return `Promise<void> | AnyAction`, and
lines 943–947
where it does `return Promise.all([dispatch(addChart(newChart, id)),
dispatch(fetchDatasourceMetadata(form_data.datasource as string))]).then(()
=> {
dispatch(addSlice(selectedSlice as Slice)); });`, showing a real caller that
expects
`dispatch(fetchDatasourceMetadata(...))` to contribute a promise to
`Promise.all`.
4. Trigger a duplicate in-flight request for the same datasource key (e.g.,
dispatch
`fetchDatasourceMetadata(KEY)` from any component or thunk, then dispatch
`addSliceToDashboard` for a slice whose `form_data.datasource` is the same
KEY before the
first request resolves). The second call hits the guard at
`datasources.ts:66–67` and
returns `undefined`; as a result, `Promise.all([... , undefined])` in
`dashboardState.ts:943–947` resolves without waiting for metadata, and any
caller awaiting
`addSliceToDashboard` neither waits for completion of the original metadata
fetch nor can
observe its rejection if it fails.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3956d671e8d141d39b2db6ec125eae83&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=3956d671e8d141d39b2db6ec125eae83&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/dashboard/actions/datasources.ts
**Line:** 66:67
**Comment:**
*Race Condition: Returning `undefined` for duplicate in-flight requests
breaks the thunk contract for callers that await this action. Any concurrent
caller (for example code using `Promise.all` with
`dispatch(fetchDatasourceMetadata(...))`) will proceed immediately instead of
waiting for metadata, and it also cannot observe a rejection if the original
request fails. Keep a per-key in-flight promise map and return the same promise
to all callers so completion/error is propagated consistently.
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%2F39894&comment_hash=cbb5a98b60e50c303297e10fe7a569620c678069b11c419ffd76b929e6ac0a1f&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39894&comment_hash=cbb5a98b60e50c303297e10fe7a569620c678069b11c419ffd76b929e6ac0a1f&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]