Trevor
Trevor

Reputation: 13457

NDB Query not returning most recently added object

I have a GAE website. The home page displays a list of project objects and a form for adding more projects. When the submit button is pressed, an ajax request is made which runs the 'create_userstoryproject()' method. This method adds the new project and returns a list of all projects, including the one that was just added. For some reason, the query in the 'create_userstoryproject()' method does not return the project just added. However, if I refresh the page, causing the 'get()' method to run, the newly added project shows up just fine. I haven't simplified this code--it's cut and pasted. Anyone have any idea why the newly created project doesn't show up until I refresh the page?

class Home(BaseApp): #BaseApp is derived from webapp2.RequestHandler
  def get(self):
    self.context['userstoryprojects'] = UserStoryProject.query().order(UserStoryProject.Order)
    self.context['userstorystatuses'] = UserStoryStatus.query().order(UserStoryStatus.Order)
    self.render('/userstories')

  def create_userstoryproject(self):
    description = self.request.get('userstoryproject[description]', default_value=None)
    if description:
      userstoryproject = UserStoryProject()
      userstoryproject.Description = description
      userstoryproject.put()
      self.context['userstoryprojects'] = UserStoryProject.query().order(UserStoryProject.Order)
      self.render('/userstoryprojects')
    else:
      self.write("fail.")

Upvotes: 1

Views: 216

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599906

This is because of eventual consistency.

Upvotes: 4

Related Questions