Reputation: 6694
Application consists of:
Problem is that the main process session doesn't seem to register changes in the db done outside that session. How do ensure it does? (as of now I am closing and reopening the session every time the process awakes and does its check).
Upvotes: 1
Views: 657
Reputation: 11315
I am closing and reopening the session every time the process awakes and does its check
SQLAlchemy will not work like this. Changes are tracked in the session.
someobj = Session.query(SomeClass).first()
puts someobj
into Session
internal cache. When you do someobj.attr = val
, it marks the change in the Session associated with someobj.
So if you pulled object1 from some session1, then closed session1, object1 is not associated with any session anymore and is not tracked.
Best solution would be to commit right upon the change:
object1 = newsession.add(object1)
newsession.commit()
Otherwise you will have to manage own objects cache and merge all of them upon each check.
Upvotes: 1