title: GAE put_multi() entities using backend NDB
body: <p>I am using a backend to write multiple entities with <code>ndb.put_multi(list_of_entities)</code>. </p>
  
  <p>The issue that I am experiencing is that just after that if I make a query then I get no results. If I put a sleep timer for eg 1 sec, I can read the entities that I just wrote. </p>
  
  <p>So eg: </p>
  
  <pre><code>class Picture(ndb.Expando):
      pass
  
  class Favourite(ndb.Expando):
      user_id = ndb.StringProperty(required=True)
      pass
  
  #...make lists with Picture and Favourite kinds
  entities = favourites
  entities[1:1] = pictures
  ndb.put_multi(entities)
  
  favourites = Favourite.query().filter(Favourite.user_id == user_id).fetch(99999, keys_only=True)
  logging.info(len(favourites)) #returns 0 in dev_appserver why?
  </code></pre>
  
  <p>First assumed the problem has to do with caching. <strong>But</strong>:</p>
  
  <p>Reading <a href="https://developers.google.com/appengine/docs/python/ndb/entities#multiple" rel="noreferrer">NDB Entities Operations on Multiple Keys or Entities</a>:</p>
  
  <blockquote>
    <p>Advanced note: These methods interact correctly with the context and
    caching; they don't correspond directly to specific RPC calls.</p>
  </blockquote>
  
  <p>Reading <a href="https://developers.google.com/appengine/docs/python/ndb/cache" rel="noreferrer">NDB Caching</a></p>
  
  <blockquote>
    <p>The In-Context Cache</p>
    
    <p>The in-context cache persists only for the duration of a single
    incoming HTTP request and is "visible" only to the code that handles
    that request. It's fast; this cache lives in memory. When an NDB
    function writes to the Datastore, it also writes to the in-context
    cache. When an NDB function reads an entity, it checks the in-context
    cache first. If the entity is found there, no Datastore interaction
    takes place.</p>
    
    <p>Queries do not look up values in any cache. However, query results are
    written back to the in-context cache if the cache policy says so (but
    never to Memcache).</p>
  </blockquote>
  
  <p>Hm I am lost here. Everything seems to be ok. Even if query from the console I get the correct sum, but never on the same handler, no matter what function etc. </p>
  
  <p>Only thing I noticed is that when put a wait <code>time.sleep(1)</code> then I get the correct results. So that has to do with the fact that the <code>ndb.put_multi</code> might not complete synchronously or not. So confused....</p>