避免在金字塔粘贴 pshell 中进行 transaction.commit 后会话过期
似乎 tansaction.commit() 是我在金字塔 paster pshell 中进行提交的唯一方法。 我知道它在提供网页方面很好,但在 shell 中,之后,在下一个 SQLAlchemy MyModel.my_attribute 调用中,我得到:
DetachedInstanceError: Parent instance <MyModel at 0x9394d0c> is not bound to
a Session; lazy load operation of attribute 'my_attribute' cannot proceed
我怎样才能避免它?
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_attribute 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
keep_session=True
传递给ZopeTransactionExtension()
来源:
https://pypi.python.org/pypi/zope.sqlalchemy #持久会话范围
Pass
keep_session=True
toZopeTransactionExtension()
Source:
https://pypi.python.org/pypi/zope.sqlalchemy#long-lasting-session-scopes
我相信这是由于 SQLA 会话的
expire_on_commit
选项造成的。执行提交后,旧事务中使用的对象必须刷新或合并到新会话中。关键是,这实际上与transaction
模块本身无关。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 thetransaction
module itself.