Reputation: 13
I have a Story model that inherits from ndb.Model, with an IntegerProperty wordCount. I'm trying to query Story objects that have a specific word count range, but the query seems to return the same results, regardless of the filter properties.
For this code:
q = Story.query()
q.filter(Story.wordCount > 900)
for s in q.fetch(5):
print s.title / s.wordCount
I get this result:
If only ... / 884
Timed release / 953
Grandfather paradox / 822
Harnessing the brane-deer / 1618
Quantum erat demonstrandum / 908
Here's the story declaration:
class Story(ndb.Model):
title = ndb.StringProperty(required=True)
wordCount = ndb.IntegerProperty('wc')
I would expect to only get stories that have 900 words exactly--or none. Inequalities and sorting are also broken. I tried deploying to GAE, and I'm seeing the same broken results.
Any ideas on what would be causing this?
Upvotes: 1
Views: 657
Reputation: 10360
NDB queries are immutable, and when you call q.filter(Story.wordCount > 900)
you're creating a new query, and not assigning it to anything. Re-assigning to your q
variable should work for you:
q = Story.query()
q = q.filter(Story.wordCount > 900)
for s in q.fetch(5):
print s.title / s.wordCount
Upvotes: 7