2

鉴于这段代码:

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
4

1 回答 1

0

I made a stupid mistake here. The session I'm using is a routing session, which has a master/slave session behind it. The fact might be that the delete is flushed to master and the query still goes to slave, so of course I can query the record again.

于 2013-11-15T07:16:52.757 回答