pyramid - pyramid什么时候提交zodb事务?

标签 pyramid zodb autocommit

我遵循了 http://docs.pylonsproject.org/docs/pyramid/en/latest/tutorials/wiki/index.html 上的教程

我知道,当我添加或更改持久对象(在本例中为 Page 对象)时,更改将不会持久化,直到 transaction.commit() 被调用。为了取消更改,我可以调用 transaction.abort()

然而,在教程中,这些调用未显示在 View 可调用对象中。我假设有一些中间件会捕获异常并在发送 HTTP 响应之前调用 .abort() 或调用 .commit(),但我不知道在代码或配置文件中的任何地方都看不到它的任何提及。

你能给我指出正确的方向吗?我只需要知道幕后发生了什么,所以我知道是否需要自己添加一些东西

最佳答案

pyramid_tm package用来;它会安装一个管理事务的 Tween。

它只是为每个请求启动一个事务,如果请求成功则事务被提交,否则中止。

来自文档:

At the beginning of a request a new transaction is started using the transaction.begin() function. Once the request has finished all of its works (ie views have finished running), a few checks are tested:

  • Did some a transaction.doom() cause the transaction to become “doomed”? if so, transaction.abort().
  • Did an exception occur in the underlying code? if so, transaction.abort() If the tm.commit_veto configuration setting was used, did the commit veto callback, called with the response generated by the application, return a result that evaluates to True? if so, transaction.abort().

If none of these checks calls transaction.abort() then the transaction is instead committed using transaction.commit().

如果出现可重试的异常(例如 ZODB 提交冲突),它还会重试 请求(从头开始重新启动它们):

When the transaction manager calls the downstream handler, if the handler raises a “retryable” exception, the transaction manager can be configured to attempt to call the downstream handler again with the same request, in effect “replaying” the request.

默认情况下禁用此行为;您可以将 tm.attempts 选项设置为大于 1 的数字以启用它。

关于pyramid - pyramid什么时候提交zodb事务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29229348/

相关文章:

plone - 我的plone站点出现POSKeyError,只在floder中损坏,其他内容正确

python - 同时修改ZODB中的不同键

java - connection.setAutoCommit = false 会发生什么

python - 是否有 Pyramid 包用于在服务器端存储表单相关信息(避免镜像隐藏字段)?

python - Python- Pyramid 和matplotlib-SVG不能超过一个 View 输出吗?

linux - Plone:RedHat Linux Server Plone 站点客户端自动停止

使用 BEGIN 和 START TRANSACTION 时 MySQL AUTOCOMMIT 状态

mysql - 为什么 START TRANSACTION 不会像它应该的那样隐式影响自动提交

python - 调试和智能感知 Pyramid 应用

python - 用于更新表的 SQLAlchemy 自定义约束