I thought too about using a check if keys are empty, but then was not sure if empty will work correctly.
So the second suggestion might work, the first not, since we will never enter the loop when wallet is empty, and subsequently return true, when indeed false would be correct.
I saw btw the discussion https://github.com/bitcoin-core/gui/pull/403 and found that a review statement there **…the pr works and the behavior after refraktor has not changed_**__ quite revealing, i tested too that PR and saw that it would not change this vital aspect, that is wrong since a lot of releases, but i guess it is not only a GUI issue and to some extent this PR is also a hint to the implications of constructions in the form of bare
for (const auto& x : X()) ...
. when we can no be sure about the size of x and make vital decisions only in the loop.