fix: make sure reads happen in transaction if there is a transaction#395
fix: make sure reads happen in transaction if there is a transaction#395chrisrossi merged 3 commits intogoogleapis:masterfrom
Conversation
Fixes a bug where reads during a transaction wouldn't necessarily happen in the context of the transaction. Fixes googleapis#394
|
Thanks @chrisrossi but it still does not work. Please change in your unittest scenario: yield [
update(id, 100, 0.01),
update(id, 100, 0.00),
]here comes the professional illustration of the problem:
WRITE1 should fail and the whole transaction replayed Thanks! |
|
I am looking at it again on master, have moved the delay to the first |
|
|
|
here's the full example I am using from google.cloud import ndb
class Simple(ndb.Model):
foo = ndb.IntegerProperty()
@ndb.transactional_tasklet()
def update(add, delay):
entity = yield Simple.get_by_id_async('one')
foo = entity.foo
foo += add
yield ndb.sleep(delay)
entity.foo = foo
yield entity.put_async()
client = ndb.Client()
@ndb.tasklet
def concurrent_tasks():
yield [
update(100, 0.01),
update(100, 0.00),
]
with client.context():
Simple(id='one', foo=42).put()
concurrent_tasks().get_result()
entity = Simple.get_by_id('one', use_cache=False)
assert entity.foo == 242 |
|
Fired it couple times and it's not deterministic |
|
I think we've hit a problem with caching.... |
|
I'm going to open back up the original ticket. This PR does fix a problem that prevented this from working, but there is also interaction with the cache which can prevent it from working as well, which should be dealt with as well, but separately from this fix. |
Fixes a bug where reads during a transaction wouldn't necessarily happen
in the context of the transaction.
Fixes #394