aminghadersohi opened a new pull request, #44096:
URL: https://github.com/apache/superset/pull/44096
### SUMMARY
**Why**
An MCP client needs to apply a viewer's filter selections without redefining
native filters or changing the saved dashboard for everyone. A permalink stores
shareable view state using the existing authorized load path; a best-effort
realtime notification can apply that state to an open dashboard without turning
a transient selection into shared configuration.
**What**
Adds `apply_dashboard_filters` for existing select and time filters, with
name/ID targeting and an optional base permalink for stacking selections across
requests. It returns a permalink and attempts a principal-scoped notification;
an open dashboard resolves that permalink, applies its selections, and offers
an eight-second Undo toast. Saved dashboard configuration is unchanged.
**Deployment requirements**
The realtime half is inert unless `WEBSOCKET_ENABLE` is on with a
coordination backend (`DISTRIBUTED_COORDINATION_CONFIG`), a running
`superset-websocket`, and a non-default `WEBSOCKET_JWT_SECRET`. The MCP process
and websocket transport must share `REALTIME_CHANNEL_PREFIX`, and the browser
user needs `can_read` on `Realtime`. With the default configuration the tool
still works and returns a permalink URL. `live_update_pushed` means publication
succeeded, not that a browser received or applied the update. No Global Task
Framework feature flag is required.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
No screenshots yet. Screenshots of the live update and Undo toast are
pending end-to-end validation.
### TESTING INSTRUCTIONS
**How to test**
**This has not been exercised in a browser yet — unit tests only.** The
steps below are proposed manual validation, not completed verification.
1. Use an MCP-enabled instance and a dashboard with existing Region (select)
and Time Range filters. As a user with dashboard read access, call:
```json
{"request":{"dashboard_id":42,"filters":[{"filter_name_or_id":"Region","values":["EMEA"]}]}}
```
Substitute the actual dashboard ID and filter name. Open the returned
`dashboard_url`; check the selection and chart queries. Verify the saved
native-filter configuration and another user's view remain unchanged.
2. Pass the response's `permalink_key` as `base_permalink_key` in a second
call applying Time Range = `2024-01-01 : 2025-01-01`. Check that Region
persists. Replace Region, clear it with `values: []`, and omit the base key to
start from dashboard defaults. Also validate required-filter behavior.
3. Try unknown/ambiguous names, duplicate targets, incorrect value types, an
inaccessible dashboard, and invalid/expired/wrong-dashboard base permalinks.
Confirm explicit errors without replacement links on base-resolution failures.
4. With all realtime prerequisites above configured, keep the dashboard open
under the same principal and repeat the call. Check chart/filter updates
without reload and the “Filters applied from chat” toast. Click Undo within
eight seconds and verify prior selections return. Check navigation during
resolution and rapid successive calls.
5. Disconnect/reconnect the socket and confirm no stale state is replayed
over manual selections or Undo. Disable websocket delivery and verify the
returned permalink remains usable.
Automated checks:
```bash
PYTHONPATH="$PWD/superset-core/src:$PWD" pytest -q \
tests/unit_tests/mcp_service/dashboard/tool/test_apply_dashboard_filters.py \
tests/unit_tests/mcp_service/dashboard/test_permalink.py \
tests/unit_tests/test_realtime_publish.py
PYTHONPATH="$PWD/superset-core/src:$PWD" pytest -q
tests/unit_tests/tasks/test_manager.py
cd superset-frontend
npm run test -- src/dashboard/useDashboardFilterSync.test.tsx
src/components/MessageToasts/Toast.test.tsx
```
Validation: 73 focused backend tests, 41 existing TaskManager tests, and 20
frontend tests passed. The full `uvx pre-commit run --files <changed files>`
gate passed without bypassing any hooks, after formatting fixes and rebuilding
stale local package declarations. No evaluation or performance run has
happened; those results are pending.
### ADDITIONAL INFORMATION
**Risk & rollback**
The shared realtime publisher can affect existing task notifications, while
live updates and Undo can overwrite affected filters' in-memory selections. The
toast action stores a callback in Redux state, so consumers expecting
serializable toast metadata deserve attention. Permalink resolution remains
behind the existing dashboard access checks. Delivery is best effort, with no
reconnect replay. Roll back by reverting this PR; no database migration or
saved filter-configuration changes need reversal. Disabling websocket delivery
stops live application but also affects other realtime consumers; permalink
creation remains available.
**Review guidance**
The riskiest hunk is the extraction of `TaskManager._publish_realtime` into
`superset/realtime/publish.py`: it is shared surface and deserves the most
scrutiny, especially callable channel-prefix resolution, envelope
compatibility, routing, and no-backend behavior. Also review the optional
`ToastMeta.action` field as an additive change to a widely imported primitive.
Check raw base-permalink merging and access enforcement, plus the frontend's
in-flight request ordering, unmount cleanup, and Undo snapshot handling.
- [ ] Has associated issue:
- [ ] Required feature flags:
- [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]