开发者

Session expire even if expire_on_commit=False when I use pyramid_tm

开发者 https://www.devze.com 2023-03-31 12:31 出处:网络
Just as the title said. All I want to do is get the return id (auto generate primary key) from the session after session.add. If I commit the transacti开发者_高级运维on manually without using pyramid_

Just as the title said. All I want to do is get the return id (auto generate primary key) from the session after session.add. If I commit the transacti开发者_高级运维on manually without using pyramid_tm all is fine, but when I start using pyramid_tm, it seems to ignore expire_on_commit. Any suggestions?


It doesn't ignore expire_on_commit, it's just that the transaction isn't committed until after your code has run, so you need to flush and refresh. This is how I do it:

thing = Thing()
Session.add(thing)
Session.flush()
Session.refresh(thing)
print thing.id
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号