鉴于这段代码:
record = session.query(Foo).filter(Foo.id == 1).first()
session.delete(record)
session.flush()
has_record = session.query(Foo).filter(Foo.id == 1).first()
我认为这里的“has_record”应该是 None ,但事实证明它与记录在同一行。
我是否错过了一些东西来获得假设的结果。或者有什么方法可以使删除在不提交的情况下生效?
Mysql 在类似的过程中会以不同的方式表现。
start transaction;
select * from Foo where id = 1; # Hit one record
delete from Foo where id = 1; # Nothing goes to the disk
select * from Foo where id = 1; # Empty set
commit; # Everything geos to the disk