pombreda / appengine-ndb-experiment

Automatically exported from code.google.com/p/appengine-ndb-experiment
Other
0 stars 0 forks source link

NDB doesn't return same instance for asynchronous gets when memcache is enabled #240

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Thanks for the report. We've fixed this as part of App Engine release 1.8.7.

Original comment by pcoste...@google.com on 12 Nov 2013 at 4:47