开发者

Avoid session expires after transaction.commit in pyramind paster pshell

Seems tansaction.commit() is the only way I have to make a commit in pyramid paster pshell. I understand it's good in serving webpages but in shell, after that, on next SQLAlchemy MyModel.my_attri开发者_如何学编程bute call I get:

DetachedInstanceError: Parent instance <MyModel at 0x9394d0c> is not bound to
a Session; lazy load operation of attribute 'my_attribute' cannot proceed

How can I avoid it?


Pass keep_session=True to ZopeTransactionExtension()

Source: https://pypi.python.org/pypi/zope.sqlalchemy#long-lasting-session-scopes


I believe this is due to the expire_on_commit option to the SQLA session. Once you perform a commit, the objects you were using with the old transaction must be refreshed or merged into the new session. The point is that this is not actually related to the transaction module itself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜