def METHOD_NAME(self, comment_id, username, value):
    session = Session()
    subquery = session.query(CommentVote).filter(
        CommentVote.username == username).subquery()
    vote_alias = aliased(CommentVote, subquery)
    q = session.query(Comment, vote_alias).outerjoin(vote_alias).filter(
        Comment.id == comment_id)
    comment, vote = q.one()
    if vote is None:
        vote = CommentVote(comment_id, username, value)
        comment.rating += value
    else:
        comment.rating += value - vote.value
        vote.value = value
    session.add(vote)
    session.commit()
    session.close()