Google app engine 在google app engine上更新ndb时多次调用put()方法

Google app engine 在google app engine上更新ndb时多次调用put()方法,google-app-engine,python-2.7,webapp2,app-engine-ndb,Google App Engine,Python 2.7,Webapp2,App Engine Ndb,我在GAE上有一个web应用程序,它使用ndb数据库,其中每个实体都有属性用户信息和两个字符串,实体类如下所示 class UserPlus(ndb.Model): user = ndb.UserProperty() dogName = ndb.StringProperty(indexed=False) catName = ndb.StringProperty(indexed=False) 主页检查是否已经存在与该用户对应的实体,如果是,则显示字符串dogName和catName的值 然后有

我在GAE上有一个web应用程序,它使用ndb数据库,其中每个实体都有属性用户信息和两个字符串,实体类如下所示

class UserPlus(ndb.Model): 
user = ndb.UserProperty()
dogName = ndb.StringProperty(indexed=False)
catName = ndb.StringProperty(indexed=False)
主页检查是否已经存在与该用户对应的实体,如果是,则显示字符串
dogName
catName
的值

然后有一个表单,用户可以在其中更新
dogName
catName
的值。这将执行对另一个页面的POST请求,下面的方法将更新实体

    def post(self): 
    currentUser = users.get_current_user()
    up = UserPlus.query(UserPlus.user==currentUser).get()
    up.dogName = self.request.get('dog_name')
    up.catName = self.request.get('cat_name')
    weatherUser.put()
    self.redirect('/')
但是当我被重定向到主页面时,
dogName
catName
的值在我刷新页面之前不会更新。我发现,在相同的位置调用
put()
方法两次而不是一次,这种情况不再发生,但我不清楚原因


是我做错了什么,还是ndb应该这样工作

正如Guido怀疑的那样,bossylobster/Fred Saur在这里回答了我的老问题——最有可能的是最终的一致性问题

您的主页如何获取用户的页面?如果是一个查询,你可能会遇到“最终一致性”。哇,代码格式不正确(不会运行),我编辑了它,我的编辑被拒绝了:D。谢谢kevin和Guido。事实上,正如您在链接的问题上所建议的那样,使用祖先查询最终解决了一致性问题