My program relies on the NDB context cache so that different ndb.Key.get()
calls will receive the same model instance.
However, I discovered that this doesn't work properly with asynchronous gets.
The expected behavior is that NDB's batcher combines the requests and return
the same model instance but that doesn't happen.
The problem only occurs when memcache is enabled which is also strange.
So far I have only tested this on the local SDK (1.8.3).
Here is a test case (run it twice):
class Entity(ndb.Model):
pass
# Disabling memcache fixes the issue
# Entity._use_memcache = False
entity_key = ndb.Key('Entity', 1)
# Set up entity in datastore and memcache on first run
if not entity_key.get():
entity = Entity(key=entity_key)
entity.put()
return
# Clear cache after Key.get() above
ndb.get_context().clear_cache()
# Entity is now in memcache and datastore but not context
entity_future_a = entity_key.get_async()
entity_future_b = entity_key.get_async()
entity_a = entity_future_a.get_result()
entity_b = entity_future_b.get_result()
# FAILS
assert entity_a is entity_b
Original issue reported on code.google.com by joachim@jkrebs.com on 19 Sep 2013 at 3:57
Original issue reported on code.google.com by
joachim@jkrebs.com
on 19 Sep 2013 at 3:57