google app engine ndb: put() and then query(), there is always one less item

前端 未结 5 1797
走了就别回头了
走了就别回头了 2021-01-11 20:36

I wonder if anybody has encountered the strange problem on Google App Engine\'s NDB: after creating a new entity and saving it by put(); and then query()<

5条回答
  •  既然无缘
    2021-01-11 21:32

    As @JesseRusak said, you need a Dummy ancestor to solve this little problem (I had the same problem that you recently).

    But I didn't make a new DummyEntity, just only a DummyKey for a DummyAncestor. Try this for your problem:

    class Item(ndb.Model): ... ... items = Item.query(ancestor=ndb.Key(Item, 'Items')).fetch() length1 = len(items) item = Item(parent=ndb.Key(Item, 'Items')) item.put() items = Item.query(ancestor=ndb.Key(Item, 'Items')).fetch() length2 = len(items)

    At least in my case, the DummyAncestor worked.

提交回复
热议问题