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.

This resolves issue #69.