Problem: Data Store Update is too slow -- after submitting a form that creates an entity, need to hit reload on the resulting page that shows the entity in the datastore.
Expected Behavior: Entity should appear in query for it, as I'm using NDB for my datastore which caches things automatically.
Problem Repro steps
- Create a default project in GoogleAppEngineLauncher 1.8.3 for Mac (my OS version is 10.8.4) and paste the code below into "main.py"
- Run the project and visit the root URL.
- Enter a number in the form and click submit.
- You'll see the text "Here's a list of entities:...end list."
- Hit Reload on your browser.
- Now you'll see the text "Here's a list of entities: [Number You Entered] ...end list."
Explanation of Expected Behavior
Since NDB automatically uses memcache, Steps 4 and 5 should not happen. After you click Submit on the form, the number you entered should show up. I observed this behavior with the regular appengine DB as well, and I know I can get around it with memcache.
Here is some code that you can drop in to the default main.py created by the AppEngineLauncher that replicates this issue:
import webapp2
from google.appengine.ext import ndb
class SmallModel(ndb.Model):
n = ndb.IntegerProperty(required=True)
stamp = ndb.DateTimeProperty(auto_now_add=True)
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world. Simple form. <form method="post"><input name="n" type="number"><input type="submit"></form>')
def post(self):
entity = SmallModel(n=int(self.request.get('n')))
entity.put()
self.redirect('/list')
class List(webapp2.RequestHandler):
def get(self):
self.response.out.write("here's a list of entities:")
entities = SmallModel.query()
for entity in entities.iter():
self.response.out.write(" %s " % entity.n)
self.response.out.write("...end list.")
app = webapp2.WSGIApplication([
('/', MainHandler),
('/list',List)
], debug=True)
Any help / advice? Thank you in advance! I've been able to repro this issue in the two browsers I tested -- Chrome and Safari.