views:

143

answers:

1

I have a user in my system who has created an entity which I'd like to retrieve. I'm attempting to do this using a filter because it's supposed to be faster than a call to the gql method. However, the filter returns no results and gql works.

randy_res = Vote.all().filter('created_by=', randy).fetch(limit=10)
randy_res = Vote.gql('WHERE created_by=:1', randy)

Is there any reason why the filter would return an empty list and the gql call would return the proper results?

+5  A: 

When using filter(), you are required to have a space between the field name and the operator. To get your filter() call to work as intended, you just need to insert a space before the equal sign:

randy_res = Vote.all().filter('created_by =', randy).fetch(limit=10)
David Underhill
ahhhhhh! this made me go insane for a night. Silent failures are my worst nightmare. I filed an issue 2 years ago, but it doesn't look like anyone else cares (only 6 stars).http://code.google.com/p/googleappengine/issues/detail?id=688
Peter Recore
Wow. You're a life saver!
Wraith
@Peter Unfortunately, it's not a bug: The original code is a perfectly valid query for the property with name 'created_by=', and any change would break this (admittedly fairly uncommon) behaviour.
Nick Johnson
sigh. I know it's not a bug in the strict sense. I do like calling it a "wart" in the api, as ryanb put it in the issues log. :) Maybe I should look into creating a rule in findbugs or eclipse that would give me a warning when it sees the lack of a space.
Peter Recore
Agreed. It might be helpful to highlight this behavior in the docs. The docs always use a space before the operator, but I don't remember seeing any tips highlighting the importance of this space.
David Underhill