Update query.py

Test for self._iter even if _iter is not part of the object. Used getattr instead.