Google App Engine Require Indexes for tests

隐身守侯 提交于 2019-12-24 06:48:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!