Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ndb.toplevel break transactions?

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?

like image 238
Sam King Avatar asked Feb 02 '14 02:02

Sam King


1 Answers

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.

like image 200
Sam King Avatar answered Sep 30 '22 09:09

Sam King