codeant-ai-for-open-source[bot] commented on code in PR #41336:
URL: https://github.com/apache/superset/pull/41336#discussion_r3459633878
##########
superset-frontend/src/pages/AlertReportList/index.tsx:
##########
@@ -168,6 +169,49 @@ function AlertList({
const [currentAlertDeleting, setCurrentAlertDeleting] =
useState<AlertObject | null>(null);
+ // Track in-flight execute requests with a ref for race-condition-safe
double-click prevention
+ const executingIdsRef = useRef<Set<number>>(new Set());
+ const { executeReport } = useExecuteReportSchedule();
+
+ const handleExecuteReport = useCallback(
+ (alert: AlertObject) => {
+ const alertId = alert.id;
+ if (!alertId) {
+ return;
+ }
+ // Atomically check-and-set before any async work to prevent duplicate
requests
+ // from rapid double-clicks that occur before a re-render can update
state.
+ if (executingIdsRef.current.has(alertId)) {
+ return;
+ }
+ executingIdsRef.current.add(alertId);
+
+ executeReport(
+ alertId,
+ () => {
+ addSuccessToast(
+ t('%(alertType)s "%(alertName)s" triggered successfully', {
+ alertType: alert.type,
+ alertName: alert.name,
+ }),
+ );
+ },
+ error => {
+ addDangerToast(
+ t('Failed to trigger %(alertType)s "%(alertName)s": %(error)s', {
+ alertType: alert.type,
+ alertName: alert.name,
+ error,
+ }),
+ );
+ },
+ ).finally(() => {
+ executingIdsRef.current.delete(alertId);
+ });
Review Comment:
**Suggestion:** The promise returned by `executeReport` is only chained with
`.finally()` and never caught, but `executeReport` rethrows on failure. This
creates unhandled promise rejections in the browser when the API call fails.
Add a `.catch()` (or stop rethrowing in the hook) so failed executions are
fully handled. [possible bug]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Browser logs unhandled rejections on failed manual executions.
- ⚠️ Global unhandled-rejection handlers may misreport these errors.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the Alerts & Reports list, which renders the `AlertList` component in
`superset-frontend/src/pages/AlertReportList/index.tsx:118-214` for a user
with
`can_write` (so `canEdit` is true) and who owns at least one alert/report.
2. In the Actions column cell (`index.tsx:23-76`), click the "Trigger now"
button added
for that row when `allowEdit` is true (`index.tsx:53-60`), which invokes
`handleExecuteReport(original)` defined at `index.tsx:176-213`.
3. `handleExecuteReport` calls `executeReport(alertId, onSuccess, onError)`
and chains
`.finally(() => { executingIdsRef.current.delete(alertId); })` at
`index.tsx:189-210`
without attaching any `.catch()` or surrounding `try/catch`.
4. The `useExecuteReportSchedule` hook in
`superset-frontend/src/features/alerts/hooks/useExecuteReportSchedule.ts:37-87`
implements
`executeReport` so that it `await SupersetClient.post({ endpoint:
\`/api/v1/report/${reportId}/execute\` })` (line 52) and, on any error,
enters the `catch`
block where it builds an error message, calls the `onError` callback (lines
79-83), and
then `throw error` (line 85). Because the only caller at
`AlertReportList/index.tsx:189-210` attaches only `.finally`, the returned
promise rejects
without any `.catch`, so when the backend endpoint
`/api/v1/report/<int:pk>/execute` in
`superset/reports/api.py:680-719` responds with a failure (e.g., 403, 422,
503 handled at
`api.py:45-56`), the browser logs an unhandled promise rejection even though
the UI error
toast is shown.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aa21917a34f542ad9e42cc30a21cca65&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=aa21917a34f542ad9e42cc30a21cca65&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/pages/AlertReportList/index.tsx
**Line:** 189:210
**Comment:**
*Possible Bug: The promise returned by `executeReport` is only chained
with `.finally()` and never caught, but `executeReport` rethrows on failure.
This creates unhandled promise rejections in the browser when the API call
fails. Add a `.catch()` (or stop rethrowing in the hook) so failed executions
are fully handled.
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%2F41336&comment_hash=1e19f570745628fa4d0b8c77aca9d23bcb83ad1bc62b21ebf59107f1880d0f79&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41336&comment_hash=1e19f570745628fa4d0b8c77aca9d23bcb83ad1bc62b21ebf59107f1880d0f79&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]