ndb.toplevel 会破坏事务吗? [英] Does ndb.toplevel break transactions?

查看:24
本文介绍了ndb.toplevel 会破坏事务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码按预期工作,不会触发断言:

The following code works as expected and does not trigger the assertion:

@ndb.transactional
@ndb.tasklet
def Foo():
  assert ndb.in_transaction()

<小时>

以下代码中断,触发断言:


The following code breaks, triggering the assertion:

@ndb.transactional
@ndb.toplevel
def Foo():
  assert ndb.in_transaction()

我尝试用 ndb.transaction 调用或 ndb.transaction_async 调用替换装饰器,但都没有奏效.

I tried replacing the decorator with an ndb.transaction call or an ndb.transaction_async call, but neither worked.

ndb.toplevel 和事务是否存在错误?

Is there a bug with ndb.toplevel and transactions?

推荐答案

我发现问题在于两者都创建了新的上下文.事务创建一个上下文并确保在其中发生的所有写入都没有冲突.toplevel 创建一个上下文并确保在其中创建的所有期货都得到解决.

I discovered that the problems is that both create new contexts. transactional creates a context and ensures that all writes that happen inside of it are non-conflicting. toplevel creates a context and ensures that all futures that are created inside of it are resolved.

因此,toplevel 正在破坏事务的上下文.这两者在当前的实现中无法结合.

As a result, toplevel is clobbering transaction's context. The two just can't be combined in their current implementation.

这篇关于ndb.toplevel 会破坏事务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆