[5.0] Fix isEmpty() bug with paginator

This fixes #6284.

Two PRs attempted to fix this (#6266, #6353) but we both made the same mistake. I (embarassingly) didn't bother to check why the tests failed.