from sqlalchemy.orm import Session
s = Session()
s.autoflush = False
s.autocommit = False
p1 = s.query(Person).first()
print p1 #prints 'Ivan Petrov', correct name of a person #1
p1.name = 'John Smith' #change the person's name
p2 = s.query(Person).first()
print p2 #prints 'John Smith', but the object wasn't flushed yet.
所以,问题是——我该如何正确处理这种情况?在我这样说之前,我需要对 p1 进行更改以不影响会话(和 p2)。