Bug description
When server pagination is enabled on a chart and the page is navigated to a higher page number (e.g., 10th page), applying a new filter with a shorter time range (which would result in fewer pages) causes the chart to not load data. It seems that the pagination is not being reset after the filter is updated, causing the chart to request data for a page that no longer exists.
How to reproduce the bug
- Enable server pagination on any chart with a significant amount of data for a specific time period (e.g., 30 days) and configure pagination with a maximum of 100 records per page.
- The chart will load with several pages of data.
- Navigate to a higher page (e.g., the 10th page).
- Update the filter to select a shorter time range (e.g., 1 day), assuming the new data set would not have as many pages as the previously selected time period.
- The chart fails to load any data, likely because it is still attempting to fetch data for the previous page number.
Screenshots/recordings
No response
Superset version
4.0.2
Python version
3.11
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
Hey @vineetdpnd! 👋 I'm here to help you with any bugs, questions, or contributions you have for Superset. Let's tackle this together!
To address the issue of pagination not resetting on charts after updating an applied filter, you can use the useEffect
hook to clear the cache and reset the page index whenever the filters change. This is already implemented in the Superset codebase as follows:
// Clear cache and reset page index if filters change
useEffect(() => {
setResponseError('');
setResultsPages(new Map());
setPageIndex(0);
}, [filters]);
This useEffect
hook ensures that whenever the filters
state changes, the responseError
is cleared, the resultsPages
cache is reset, and the pageIndex
is set to 0. This effectively resets the pagination to the first page, avoiding loading issues [1].
Additionally, in the buildQuery
function, there is logic to reset the row_offset
to 0 if the filters have changed, ensuring that the pagination starts from the first page:
if (
formData.server_pagination &&
options?.extras?.cachedChanges?.[formData.slice_id] &&
JSON.stringify(options?.extras?.cachedChanges?.[formData.slice_id]) !==
JSON.stringify(queryObject.filters)
) {
queryObject = { ...queryObject, row_offset: 0 };
updateExternalFormData(
options?.hooks?.setDataMask,
0,
queryObject.row_limit ?? 0,
);
}
This ensures that the pagination is reset on the server side as well, providing a consistent experience when filters are updated [2].
To continue talking to Dosu, mention @dosu.
Comment From: vineetdpnd
We have checked it, the limit & offset value is not reset on the queries post change of the applied filters, so it does seem to be bug
Comment From: rusackas
Hey all... this hasn't been touched in quite a while. Can anyone validate if this is still an issue on 4.1.2 and/or 5.0.0rc2? If not, this is at risk of being closed as stale/not-planned
Comment From: rusackas
We haen't heard back here with validation/corroboration, so I'll assume this is all good now. I'm unable to replicate this on Preset, so I think it's resolved.