Fixed #23875 -- cleaned up query.get_count()

The query.get_count() can be significantly cleared up due to expressions API changes.
I'm not clear on the logic of this check: why is it correct, why does it belong here, where will this exception be caught and handled?

I'm sure it's correct, but maybe you could point me in the right direction so I understand it :-)