aminghadersohi opened a new pull request, #45242:
URL: https://github.com/apache/superset/pull/45242
### SUMMARY
`apply_dashboard_filters` put any requested `filter_select` value straight
into the permalink's `IN` predicate. If the column did not contain the value
(for example "Asia Pacific" when the data holds "APAC"), every chart in the
filter's scope went empty, yet the tool still returned a permalink and the
assistant reported success.
With this change, each requested select value is checked against the filter
column's distinct values before any permalink is written. The check uses
`values_for_column`, the same bounded, RLS-aware query that feeds the select
filter's options, and the same `raise_for_access` gate as the column-values API:
- **Exact match:** applied as given.
- **Single match ignoring case and spacing** (`"emea"` → `"EMEA"`, `"2024"`
→ `2024`): applied with the column's own spelling. `applied_filters` reports
the corrected value.
- **No match:** the call fails and no permalink is written. The error lists
the closest matches (substring or `difflib`), or else a sample of the available
values, and tells the caller to offer those values instead of reporting
success. If one value in a multi-filter request is unknown, the whole request
fails.
- **Several values match ignoring case** (`"APAC"` and `"apac"`): treated as
no match rather than guessed.
If the first page of values is truncated (`FILTER_SELECT_ROW_LIMIT`), a
full-column search confirms the value is absent before rejecting it. NULL, or a
value whose search query fails, is kept as given, because absence from a
truncated page proves nothing.
If the values cannot be read at all (unresolvable or inaccessible dataset,
query failure), the request is applied unchecked, as before, so the check never
blocks a filter it cannot verify. Clearing a selection (`values: []`) reads no
data.
The tool docstring and the `values` field description now say values must
exist in the column. The tool's inventory byte budget is unchanged.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (MCP tool, backend only).
Before: `{"filter_name_or_id": "Region", "values": ["Asia Pacific"]}`
returned a permalink, and the dashboard opened with every chart empty.
After:
```
Filter 'Region' has no value 'Asia Pacific' in column 'region', so applying
it would leave every chart it filters empty. No filter values were applied.
Available values: 'APAC', 'EMEA', 'LATAM', 'North America' (4 in total). Tell
the user the value was not found and offer these values instead of reporting
the filter as applied.
```
### TESTING INSTRUCTIONS
```
pytest
tests/unit_tests/mcp_service/dashboard/tool/test_apply_dashboard_filters.py
tests/unit_tests/mcp_service/test_tool_inventory.py
```
The new tests cover:
- missing-value rejection, including inside a multi-filter request
- suggestions for partial and misspelled values
- case and spacing correction, and text matching a numeric value
- ambiguous case-insensitive matches
- truncated first page: search hit, search miss, NULL handling, failed search
- unreadable datasets: none resolved, access denied, query error
- empty column
- `True` and `1` kept as distinct selections
- one end-to-end test that runs the real `values_for_column` query against
SQLite
Ten of the new tests fail on master.
Manual check: ask an MCP client to filter a dashboard's select filter to a
value the column does not contain. The tool should return an error that lists
the real values, and no permalink.
### 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
- [ ] 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]