SkinnyPigeon opened a new pull request, #41336:
URL: https://github.com/apache/superset/pull/41336

   
   ### SUMMARY
   Aims to replace 
https://github.com/apache/superset/pull/35083#pullrequestreview-4548258396.
   
   Adds an on-demand execution button to the Alerts & Reports list view, 
allowing owners to immediately trigger a report or alert without waiting for 
the next scheduled run. This is useful for testing, debugging, and one-off 
delivery.
   
   **Backend**
   
   - New `POST /api/v1/report/{pk}/execute` endpoint, protected by `@protect()` 
(ownership check via `security_manager.raise_for_ownership`).
   - New `ExecuteReportScheduleNowCommand` that enqueues a Celery task via 
`execute.apply_async`, setting `eta=datetime.now(tz=timezone.utc)` so the 
downstream task receives a valid `scheduled_dttm`.
   - Working timeout is forwarded from the schedule model when set.
   - Two new exception classes:
     - `ReportScheduleExecuteNowFailedError` (422) — general execution failure
     - `ReportScheduleCeleryNotConfiguredError` (503) — Celery broker 
unreachable
   - New `ReportScheduleExecuteResponseSchema` with `execution_id` (UUID) and 
`message` fields.
   
   **Frontend**
   
   - New `useExecuteReportSchedule` hook (`src/features/alerts/hooks/`) that 
calls the endpoint and returns `{ executeReport, loading, error }`.
   - A ⚡ **Trigger now** action button (using `ThunderboltOutlined` icon) added 
to each row in the Alerts & Reports list, positioned between Edit and Delete.
   - Success and error outcomes shown as toast notifications.
   - Race condition prevention using `useRef<Set<number>>` — a clicked row is 
locked until the request resolves, preventing double-triggers.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   **Before:** No way to manually trigger a report from the list view without 
editing the schedule or using the CLI.
   
   **After:** A ⚡ "Trigger now" action icon appears in the list row actions. 
Clicking it immediately dispatches the report via Celery and shows a success 
toast with the execution ID.
   
   ### TESTING INSTRUCTIONS
   
   1. Navigate to **Alerts & Reports**.
   2. Click the ⚡ icon on any row you own.
   3. A success toast should appear: _"Report schedule execution started"_.
   4. Verify the execution appears in the report log (check Celery worker logs 
or the report history).
   
   **To test error handling:**
   - Temporarily stop the Celery worker and click ⚡ — should show a 503 toast.
   - Click ⚡ on a report you don't own (as a non-admin) — the button should not 
be visible.
   
   **API (curl):**
   ```bash
   # Login and get CSRF token first, then:
   curl -X POST http://localhost:8088/api/v1/report/{pk}/execute \
     -H "Authorization: Bearer $TOKEN" \
     -H "X-CSRFToken: $CSRF"
   # Expected 200: {"execution_id": "<uuid>", "message": "Report schedule 
execution started successfully"}
   # Expected 404: report not found
   # Expected 403: not the owner
   # Expected 503: Celery not reachable
   ```
   
   **Python integration tests:**
   ```bash
   scripts/tests/run.sh --module tests/integration_tests/reports/api_tests.py 
-k "execute" -v
   ```
   
   **JS unit tests:**
   ```bash
   cd superset-frontend
   npm run test -- --testPathPatterns="useExecuteReportSchedule|AlertReportList"
   ```
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags: requires `ALERT_REPORTS` feature flag to be 
enabled (same as the existing Alerts & Reports feature)
   - [x] Changes UI
   - [ ] Includes DB Migration
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   Closes #35083 (re-implementation of the abandoned PR with reviewer 
improvements applied).
   
   **Key improvements over the original PR:**
   - `eta` is set on the Celery task so `scheduled_dttm` is never null in the 
task execution
   - Race condition guard uses `useRef<Set<number>>` instead of `useState` to 
avoid stale closure issues
   - Error type is `Response` (the actual shape thrown by `SupersetClient`) 
rather than a manually cast `any`
   - Celery connectivity errors detected via string keyword matching → 503; all 
others → 422
   - Tests use `@pytest.mark.usefixtures("create_report_schedules")` fixture 
pattern rather than ad-hoc setup
   


-- 
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]

Reply via email to