user605331
user605331

Reputation: 3788

How are listproperty fields ordered in App Engine?

I am planning to store some data in a listproperty and want to be sure that the order of the items in the list remains the same when I query my entity back out. Is there such a guarantee when putting and getting data from the datastore?

To be clear, I am not trying to order a set of results by anything in the listproperty, I just want to make sure that if I have a list of strings (for example: "Sam", "Alberto", "Rick"), they are always in that order when I access that entity.

The answer to this question would imply that they do always stay the same, but I'd like to be sure: Use a ListProperty or custom tuple property in App Engine?

Upvotes: 1

Views: 620

Answers (2)

user458962
user458962

Reputation:

The statement from the documentation is:

Order is generally preserved, so when entities are returned by queries and get(), the list properties values are in the same order as when they were stored. There's one exception to this: Blob and Text values are moved to the end of the list; however, they retain their original order relative to each other.

(From http://code.google.com/appengine/docs/python/datastore/datamodeling.html)

So, if you are only storing strings, they should be returned in the correct order.

Upvotes: 4

Wooble
Wooble

Reputation: 89897

ListProperties work just like python lists; they are ordered and will remain ordered.

Upvotes: 1

Related Questions