Avoid StaleDataError exception during user.recalculate_attitude()

This commit is contained in:
rimu 2024-11-02 16:34:16 +13:00
parent f36135d163
commit 915e8c779a

View file

@ -895,6 +895,7 @@ class User(UserMixin, db.Model):
def recalculate_attitude(self):
upvotes = downvotes = 0
with db.session.no_autoflush: # Avoid StaleDataError exception
last_50_votes = PostVote.query.filter(PostVote.user_id == self.id).order_by(-PostVote.id).limit(50)
for vote in last_50_votes:
if vote.effect > 0: