我只是因为我的功能测试没有使用与我的 dev_appserver 相同的设置而感到不满。我目前使用 require_indexes 运行我的 dev_appserver(非 rel)。
如何强制我的测试台使用相同的设置?
我尝试过使用 SetupIndexes
但它并不“要求”在我的 index.yaml 中定义它们。我的设置不正确,因此我可以执行任何我想要的查询。
即
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.
但是当查询在服务器上执行时我得到了
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:
最佳答案
尝试将 { "require_indexes": True } 添加为 init_datastore_v3_stub() 的关键字参数
您可以查看(并单步执行)SDK 代码以了解该参数最终是如何传递到数据存储 stub 中的。
关于python - Google App Engine 需要索引进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622683/