google-app-engine – devappserver2,remote_api和–default_partition

要使用原始dev_appserver在本地访问远程数据存储区,我将设置–default_partition = s,如上所述
here

2013年3月,Google将devappserver2作为默认开发服务器,并且它不支持–default_partition导致原始的,可怕的:

BadRequestError: app s~appname cannot access app dev~appname's data

似乎前几个请求正确提供

os.environ["APPLICATION_ID"] == 's~appname'

然后,后续请求会调用/ _ah / warmup然后调用

os.environ["APPLICATION_ID"] == 'dev~appname'

文档特别提到相关主题,但似乎面向dev_appserver here

Warning! Do not get the App ID from the environment variable. The development server simulates the production App Engine service. One way in which it does this is to prepend a string (dev~) to the APPLICATION_ID environment variable, which is similar to the string prepended in production for applications using the High Replication Datastore. You can modify this behavior with the –default_partition flag, choosing a value of “” to match the master-slave option in production. Google recommends always getting the application ID using the get_application_id() method, and never using the APPLICATION_ID environment variable.

最佳答案 你可以做以下肮脏的小技巧:

from google.appengine.datastore.entity_pb import Reference

DEV = os.environ['SERVER_SOFTWARE'].startswith('Development')

def myApp(*args): 
    return os.environ['APPLICATION_ID'].replace("dev~", "s~")

if DEV:
    Reference.app = myApp
点赞