aminghadersohi opened a new pull request, #44893:
URL: https://github.com/apache/superset/pull/44893
### SUMMARY
The MCP dashboard tools could already *read* all four native filter types
(`filter_select`, `filter_time`, `filter_range`, `filter_timegrain`) via
`get_dashboard_info`, but `apply_dashboard_filters` and `manage_native_filters`
only supported *creating and setting values on* `filter_select` and
`filter_time`. A client could be told a numeric range or time-grain filter
existed on a dashboard and then have no way to change it.
This PR adds `filter_range` and `filter_timegrain` support to both tools,
each with its own data-mask shape matching what the corresponding frontend
filter plugin (`Range`, `TimeGrain`) produces:
- **`apply_dashboard_filters`**: new `range` (`[lower, upper]`) and
`time_grain` (a list of at most one value) fields on each filter spec.
- `range` mirrors the frontend's `getRangeExtraFormData`: distinct bounds
become a `>=`/`<=` predicate pair, equal bounds collapse to a single `==`
predicate, and `[null, null]` clears the filter (produces no predicate).
- `time_grain` sets `extraFormData.time_grain_sqla`; an empty list clears
the filter.
- Clearing either filter when it is marked `enableEmptyFilter` is
rejected, matching the existing `filter_time` behavior.
- **`manage_native_filters`**: new `FilterRangeSpec` and
`FilterTimeGrainSpec` creation specs (discriminated by `filter_type`), and the
existing `dataset_id`/`column`/`enable_empty_filter` update fields on
`NativeFilterUpdateSpec` now also apply to these two types where relevant.
Per-type validation now rejects update fields that don't apply to a given
filter's type (e.g. `multi_select` on a `filter_range` filter).
**Deliberately out of scope:**
- `filter_timecolumn` (the fifth native filter type) remains unsupported on
every path, read included. It's called out explicitly in both tools'
docstrings/schema descriptions rather than silently omitted.
- `cascadeParentIds` (cascading/parent filter dependencies) remains
read-only; it is not exposed as a settable field on create/update. Filter
*scoping* (`scope_chart_ids`) is unaffected.
Both existing safety properties are preserved: unsupported filter types and
malformed values are rejected with an explicit error rather than guessed at.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable — this is a backend/MCP-tool-only change with no UI.
### TESTING INSTRUCTIONS
Unit tests cover both tools for both new filter types, valid and invalid
inputs:
```
pytest
tests/unit_tests/mcp_service/dashboard/tool/test_apply_dashboard_filters.py
pytest
tests/unit_tests/mcp_service/dashboard/tool/test_manage_native_filters.py
```
New coverage includes:
- `apply_dashboard_filters`: distinct/equal/one-sided range bounds, clearing
an optional range, rejecting a clear on a required range, rejecting `lower >
upper`, applying and clearing a time grain, rejecting a clear on a required
time grain, rejecting an unrecognized time grain string, and cross-type field
mismatches (e.g. `range` on a `filter_select` filter).
- `manage_native_filters`: creating a `filter_range` filter (dataset/column
target, `enable_empty_filter`), creating a `filter_timegrain` filter,
invalid-column rejection, updating a range filter's target and
`enable_empty_filter`, updating a time-grain filter's `enable_empty_filter`,
and rejecting type-incompatible update fields in both directions
(`dataset_id`/`column` on `filter_timegrain`, `multi_select` on `filter_range`).
Also ran the full `tests/unit_tests/mcp_service/dashboard` suite (711 tests)
to confirm no regressions, and `pre-commit run` (mypy, ruff, ruff-format,
pylint) on all changed files.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] 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]