speedplane
speedplane

Reputation: 16121

Using a Sort Order Breaks Google App Engine Queries

I'm having a problem with my app-engine queries. When I run my query without sort order, everything works just fine:

q = models.Contact.all();
q.filter("location = ", x);
if(cur_search_cursor != None):
   q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();

The above query properly returns values. However, if I simply add a sort order to the first line, nothing is returned at all:

q = models.Contact.all().order('name');
q.filter("location = ", x);
if(cur_search_cursor != None):
   q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();

No exception is raised, but no entities are returned either. Is there a bug in my code? Or do I have to do something special in my index.yaml file to get this to work?

I'm trying this on the dev_server with sqlite turned off. I haven't tried testing it on the actual GAE.

Upvotes: 0

Views: 669

Answers (1)

speedplane
speedplane

Reputation: 16121

Figured it out... the 'name' field is a TextProperty. A TextProperty is not orderable, as per the documentation: http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html

That was a waste of three hours.

Upvotes: 4

Related Questions