def model_query(self, model, session=None):
        session = session or get_session()
        query = session.query(model)

        def issubclassof_rally_base(obj):
            return isinstance(obj, type) and issubclass(obj, models.RallyBase)

        if not issubclassof_rally_base(model):
            raise Exception(_("The model should be a subclass of RallyBase"))

        return query
The helper method to create query.
dataset/ETHPy150Open openstack/rally/rally/common/db/sqlalchemy/api.py/Connection.model_query