These lines belong **within** the else-block! and the check needs to be done before the ``query`` might be updated.

Use a better error message such as ``"The attribute {0!r} is not supported to query a database".format(typ)``