def METHOD_NAME(query, page_number, page_size):
    if page_number is not None:
        if page_number < 1:
            raise Exception("Page number should be positive: {}".format(page_number))
        query = query.offset((page_number - 1) * page_size)
    return query