richardfogaca opened a new pull request, #36109:
URL: https://github.com/apache/superset/pull/36109
### SUMMARY
Fixes a bug where the `/api/v1/dataset/warm_up_cache` API endpoint was not
applying dashboard filters to non-legacy visualizations
**Issue:** When warming up cache with a `dashboard_id` parameter, legacy
visualizations correctly applied dashboard default filters, but non-legacy
visualizations ignored them completely, caching unfiltered data.
**Root cause:** In `superset/commands/chart/warm_up_cache.py`, the
non-legacy visualization code path (lines 77-108 in original) did not check for
`dashboard_id` or retrieve dashboard filters, unlike the legacy path which
properly called `get_dashboard_extra_filters()`.
**Solution:**
- Added dashboard filter retrieval and application logic to the non-legacy
visualization path
- Refactored code to extract `_get_dashboard_filters()` helper method (DRY
principle)
- Split legacy and non-legacy logic into separate methods to reduce
complexity (C901)
- Added 5 comprehensive unit tests to validate filter application
**Changes:**
1. New method `_get_dashboard_filters()`: Retrieves filters from
`extra_filters` parameter or dashboard metadata
2. Enhanced `_warm_up_non_legacy_cache()`: Applies dashboard filters to
each query in the query context
3. Refactored `run()`: Reduced complexity from 11 to 3 by delegating to
helper methods
The fix mirrors the existing legacy visualization pattern, ensuring
consistent behavior across all visualization types.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend API change only
### TESTING INSTRUCTIONS
1. Create a dataset and a chart using a non-legacy visualization (e.g.,
`echarts_timeseries_bar`, `pie`, `big_number`)
2. Add the chart to a dashboard
3. Configure default filters in the dashboard's `json_metadata`:
```json
{"default_filters": "{\"<chart_id>\": {\"<column_name>\":
[\"<value>\"]}}"}
4. Call the warm_up_cache API:
PUT /api/v1/dataset/warm_up_cache
{
"db_name": "your_database",
"table_name": "your_table",
"dashboard_id": <dashboard_id>
}
5. Verify the chart data is cached with the dashboard filters applied
(check SQL logs or cache keys)
--
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]