diff --git a/files/classes/comment.py b/files/classes/comment.py index 26c0816d4..0bc447fde 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -135,8 +135,8 @@ class Comment(Base): @lazy def total_choice_voted(self, v): if v: - return g.db.query(CommentVote.comment_id).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() - return False + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() + return None @property @lazy diff --git a/files/classes/submission.py b/files/classes/submission.py index 596deed5f..3611c0dcb 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -128,8 +128,8 @@ class Submission(Base): @lazy def total_choice_voted(self, v): if v and self.choices: - return g.db.query(CommentVote.comment_id).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() - return False + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).first() + return None @lazy def total_bet_voted(self, v): diff --git a/files/routes/votes.py b/files/routes/votes.py index fbeac116c..f76583431 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -278,7 +278,8 @@ def api_vote_choice(comment_id, v): if comment.parent_comment: parent = comment.parent_comment else: parent = comment.post - for vote in parent.total_choice_voted(v): + vote = parent.total_choice_voted(v) + if vote: vote.comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1 g.db.add(vote.comment) g.db.delete(vote)