devappserver2, remote_api, and --default_partition

China☆狼群 提交于 2020-02-01 04:51:05

问题


To access a remote datastore locally using the original dev_appserver I would set --default_partition=s as mentioned here

In March 2013 Google made devappserver2 the default development server, and it does not support --default_partition resulting in the original, dreaded:

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

It appears like the first few requests are served correctly with

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

Then a subsequent request results in a call to /_ah/warmup and then

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

The docs specifically mention related topics but appear geared to 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.


回答1:


You can do the following dirty little trick:

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


来源:https://stackoverflow.com/questions/16287790/devappserver2-remote-api-and-default-partition

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