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..

Answers


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.


Need Your Help

Compare two HTML elements view using jquery (and | or) with Canvas

javascript jquery webkit html5-canvas

I have text DIV's like below. I am targeting only non IE and webkit browsers.

How to change Xcode's SplitView template - tableview on the right, detail view on the left

iphone objective-c xcode

I am using XCode's splitview template. I want the list of items to be on the right when in landscape mode - is this a quick change - can someone give me some pointers if possible.

Passing URL variable via HTML form submission using either PHP or JavaScript

php javascript forms url variables

I need to simply pass a form variable into a URL variable. I suspect that it's something easy to do but I'm having a hard time finding clear steps (that aren't tons of code) online anywhere.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.