Question

class MyEntity(db.Model):
    timestamp = db.DateTimeProperty()
    title = db.StringProperty()
    number = db.FloatProperty()

db.GqlQuery("SELECT * FROM MyEntity WHERE title = 'mystring' AND timestamp >= date('2012-01-01') AND timestamp <= date('2012-12-31') ORDER BY timestamp DESC").fetch(1000)

This should fetch ~600 entities on app engine. On my dev server it behaves as expected, builds the index.yaml, I upload it, test on server but on app engine it does not return anything.

Index:
- kind: MyEntity
  properties:
  - name: title
  - name: timestamp
    direction: desc

I try splitting the query down on datastore viewer to see where the issue is and the timestamp constraints work as expected. The query returns nothing on WHERE title = 'mystring' when it should be returning a bunch of entities.

I vaguely remember fussy filtering where you had to call .filter("prop =",propValue) with the space between property and operator, but this is a GqlQuery so it's not that (and I tried that format with the GQL too).

Anyone know what my issue is?

One thing I can think of: I added the list of MyEntity entities into the app via BulkLoader.py prior to the new index being created on my devserver & uploaded. Would that make a difference?

Was it helpful?

Solution 2

Turns out there's a slight bug in the bulkloader supplied with App Engine SDK - basically autogenerated config transforms strings as db.Text, which is no good if you want these fields indexed. The correct import_transform directive should be:

transform.none_if_empty(str)

This will instruct App Engine to index the uploaded field as a db.StringProperty().

OTHER TIPS

The last line you wrote is probably the problem.

Your entities in the actual real datastore are missing the index required for the query.

As far as I know, when you add a new index, App Engine is supposed to rebuild your indexes for you. This may take some time. You can check your admin page to check the state of your indexes and see if it's still building.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top