DamianPendrak opened a new pull request, #46037:
URL: https://github.com/apache/superset/pull/46037
### SUMMARY
Adds an optional per-dashboard auto-refresh policy behind a new feature
flag, `AUTO_REFRESH_POLICY` (default `False`). With the flag off nothing
changes; a stored policy is kept but ignored.
With the flag on, dashboard owners can turn on **Use a refresh policy** in
Dashboard properties → Refresh settings and set:
- **Allow auto-refresh.** When off, viewers get no auto-refresh menu item,
status indicator or timer, embedded dashboards included. Manual refresh stays.
- Optional **Shortest** and **Longest** intervals from
`DASHBOARD_AUTO_REFRESH_INTERVALS`. Viewers can only pick intervals inside that
range, and the default refresh frequency must be inside it too.
The policy is stored in `json_metadata` under `auto_refresh_policy`:
```json
{
"refresh_frequency": 60,
"auto_refresh_policy": {
"auto_refresh_allowed": true,
"custom_refresh_allowed": false,
"minimum_refresh_interval": {"value": 30, "unit": "seconds"},
"maximum_refresh_interval": {"value": 1, "unit": "hours"}
}
}
```
The dashboard API, copy, imports, MCP tools and version restore all validate
it. Invalid values return 422 with an `errors` list of `{field, code,
message}`. An update that omits `auto_refresh_policy` keeps the stored policy;
`null` removes it. Policy changes are recorded in the existing `Log` table. No
DB migration.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<img width="500" height="990" alt="01-properties-no-policy"
src="https://github.com/user-attachments/assets/3352b707-0eaf-434f-bf6b-cec0ffcadeef"
/>
<img width="500" height="956" alt="02-properties-allowed-bounds"
src="https://github.com/user-attachments/assets/8ce3ae59-e97b-4c50-80e7-4f11d92cd336"
/>
<img width="400" height="446" alt="06-viewer-interval-modal"
src="https://github.com/user-attachments/assets/a21165fb-8625-436c-bb10-ee231ecc331e"
/>
### TESTING INSTRUCTIONS
1. Set `FEATURE_FLAGS = {"AUTO_REFRESH_POLICY": True}` and restart.
2. Open a dashboard → Edit properties → Refresh settings → turn on **Use a
refresh policy**.
3. Keep **Allow auto-refresh** on, pick Shortest 1 minute and Longest 1
hour, a default of 5 minutes, Apply and Save. As a viewer, open ⋯ → Update
auto-refresh: only intervals between 1 minute and 1 hour are listed and the
range is stated.
4. Back in properties, lower Longest below the default: the default shows an
inline error and Apply is disabled until it is fixed.
5. Turn **Allow auto-refresh** off with a positive default: an error asks
for "Don't refresh"; pick it, Save. Reload: the auto-refresh menu item, status
indicator and timer are gone; manual "Refresh dashboard" stays. Open the
dashboard embedded (or `?standalone=true`): no automatic refresh.
6. API: `PUT /api/v1/dashboard/<id>` with `json_metadata` containing a
`refresh_frequency` below `minimum_refresh_interval` → 422 with an `errors`
entry `{"field": "refresh_frequency", "code": "below_minimum", ...}`. A PUT
that omits `auto_refresh_policy` keeps it; sending `null` removes it.
7. Copy the dashboard (Save as): the copy keeps the policy.
8. Set the flag back to `False` and restart: Refresh settings and the header
menu are stock again, and saves succeed with the stored policy left in
`json_metadata`.
Automated: `pytest tests/unit_tests/dashboards
tests/unit_tests/mcp_service/dashboard` and `npm run test --
src/dashboard/components/PropertiesModal
src/dashboard/components/RefreshFrequency src/dashboard/components/Header
src/dashboard/components/RefreshIntervalModal`.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [x] Required feature flags: `AUTO_REFRESH_POLICY` (new, default `False`)
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]