Search code examples
google-app-enginepython-2.7webapp2app-engine-ndb

Multiple calls to put() method when updating ndb on google app engine


I have a web app on GAE which uses a ndb database where each entity has as properties user informations and two string, the Entity class is like the one below

class UserPlus(ndb.Model): 
user = ndb.UserProperty()
dogName = ndb.StringProperty(indexed=False)
catName = ndb.StringProperty(indexed=False)

The Main Page check if there's already an entity corresponding to that user, and if yes displays the value of the strings dogName and catName.

Then there's a form where users can update the values of dogName and catName . This performs a POST request to another page, the method below update the entiy

    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('/')

But when I'm redirected to the Main Page, the values of dogName and catName are not updated until I refresh the page. I found that by calling the put() method two times instead of one, in the same position, this doesn't occur anymore, but I don't have clear why.

Am I doing something wrong or it's how ndb is supposed to work?


Solution

  • As Guido suspects and bossylobster/Fred Saur answered on my old question here - Should I expect stale results after redirect on local environment? - most likely eventual consistency problem.