I'm creating a simple notification system for a website. The user's notifications are pulled from the database, marked as seen if they haven't been already, and then displayed to the user. The ones that were unseen are displayed in bold. Here's some of my code:
query = request.db.query(Notification)\
.filter(Notification.user == request.user)
notifications = query.order_by(Notification.created_at.desc()).all()
print [ notif.seen for notif in notifications ] # [ False, False, False... ]
query.filter(Notification.seen == False).update({
'seen': True
})
request.db.commit()
print [ notif.seen for notif in notifications ] # [ True, True, True... ]
You'll notice from my print statements that notifications is modified when the update query is executed, despite already being pulled from the database with .all().
I don't want this behavior. I need to see what notifications was, not what it is, in order to bold the fields that have previously been unseen.
Looking through the docs, I thought setting the synchronize_session argument to False might work.
query.filter(Notification.seen == False).update({
'seen': True
}, False)
But unfortunately, it did not.
How might I fix this?