问题
I just got bit by my functional tests not using the same settings as my dev_appserver. I currently run my dev_appserver (non-rel) with require_indexes.
How to I force my test bed to use the same setings?
I have tried using SetupIndexes but it did not "require" they be defined in my index.yaml. I did not have the setting correct and as a result i can do any query I want.
i.e.
clz.testbed = Testbed()
clz.testbed.activate()
clz.testbed.init_memcache_stub()
clz.testbed.init_taskqueue_stub()
clz.testbed.init_urlfetch_stub()
clz.testbed.init_datastore_v3_stub(use_sqlite=True, datastore_file=somepath)
SetupIndexes('','')
model.objects().filter(x=1, y=2.....) #will work regardless of index defined.
but when the query executes on the server i get the
NeedIndexError: This query requires a composite index that is not defined. You must update the index.yaml file in your application root. The following index is the minimum index required:
回答1:
Try adding { "require_indexes" : True } as a keyword argument to init_datastore_v3_stub()
You can look through (and step through) the SDK code to see how that parameter is eventually passed into the datastore stub.
来源:https://stackoverflow.com/questions/11622683/google-app-engine-require-indexes-for-tests