简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM