use getattr() with default intead of hasattr()

When asking for the query attribute, use getattr('query', None)
rather than hasattr('query').  This prevents errors if a 'query'
attribute is available but empty or None.
Merge pull request #70 from larsks/bug/69

use getattr() with default intead of hasattr()