Newly added record in datastore is not refelcting in the application
I have been facing this problem in app engine. As I am new to App Engine, I don't know whether I am doing it right way or not.
Whenever a new record is inserted into datastore, this newly inserted record doesn't reflect in the application. It will appear only after next reload.
This is the simple code: Adding a user and just printing all users from the User table:
def add_user(name): u = User(name = name) u.put() all_users = [u.name for u in User.all().order('name')] #On printing 'all_users', it doesn't show recently added user
Is this the common behaviour in App Engine. Does it take time to add new record in datastore? Is there anything wrong in the way record is inserted? Please help..
You should never consider using sleep.
What you are seeing is "eventual consistency" in the HRD. Have a read of "Structuring Data for Strong Consistency" https://developers.google.com/appengine/docs/python/datastore/structuring_for_strong_consistency which describes strategies for making strongly consistent queries.
As an aside, if you have just put() a user entity, you don't need to query for it, you already have it.