server/comments: fix serializing cached scores

This commit is contained in:
rr- 2016-06-12 14:01:38 +02:00
parent 7e8a9a0948
commit a67db59d99
2 changed files with 2 additions and 2 deletions

View File

@ -35,7 +35,8 @@ class Comment(Base):
@property @property
def score(self): def score(self):
return object_session(self) \ from szurubooru.db import session
return session \
.query(func.sum(CommentScore.score)) \ .query(func.sum(CommentScore.score)) \
.filter(CommentScore.comment_id == self.comment_id) \ .filter(CommentScore.comment_id == self.comment_id) \
.one()[0] or 0 .one()[0] or 0

View File

@ -33,7 +33,6 @@ def test_simple_rating(test_ctx, fake_datetime):
test_ctx.context_factory(input={'score': 1}, user=user), test_ctx.context_factory(input={'score': 1}, user=user),
comment.comment_id) comment.comment_id)
assert 'text' in result assert 'text' in result
comment = db.session.query(db.Comment).one()
assert db.session.query(db.CommentScore).count() == 1 assert db.session.query(db.CommentScore).count() == 1
assert comment is not None assert comment is not None
assert comment.score == 1 assert comment.score == 1