Search code examples
google-app-enginegoogle-cloud-datastoregqlbulkloader

GQL Query Not Returning Results on StringProperty Query Test for Equality


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?


Solution

  • 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().