views:

98

answers:

1

I just noticed a strange result from a query that I have trouble understanding. It appears as if adding an order() to a Query is limiting the results I get back.

Here is my interaction:

>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
    SomeModel.all().filter('action =', 'foo').count()
(192L, 293L)

>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
    SomeModel.all().filter('action =', 'foo').count()
(193L, 294L)

As you can see, a hundred entities were not added between the two queries. It seems like the order() instruction is limiting the result set. But created_at is a required property and is present in all entities.

>>> count = 0
>>> for entity in SomeModel.all().filter('action =', 'foo'):
...   if not entity.created_at:
...     raise Exception, 'Not found!'
...   count += 1
...
>>> print count
361

No exceptions. So why would the query with the ORDER not return all entities?

Finally, investigating whether it's bad data:

>>> print "ascending=%d no-filter=%d descending=%d" % (
      SomeModel.all().filter('action =', 'foo').order('created_at').count(),
      SomeModel.all().filter('action =', 'foo').count(),
      SomeModel.all().filter('action =', 'foo').order('-created_at').count())
ascending=79 no-filter=179 descending=173
A: 

The problem has disappeared despite not having changed my code. The best guess I have is that maybe the index fell behind, although I had assumed that if I get a successful return from put() then the indexes are updated.

jhs