Does ndb.toplevel break transactions?
Asked Answered
A

1

7

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()

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

Is there a bug with ndb.toplevel and transactions?

Altman answered 2/2, 2014 at 2:12 Comment(1)
The only purpose of ndb.toplevel is to set a fresh default context. So I don't understand the use of ndb.transactional(ndb.toplevel(Foo())). Why need you to create a transaction AND then delete it's context?Floridafloridia
A
6

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.

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

Altman answered 28/2, 2014 at 19:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.