App Engine SDK DevServer Read-Only Mode?

后端 未结 1 949
粉色の甜心
粉色の甜心 2021-02-07 18:00

Is there a way to run the app engine dev server in read-only mode in order to simulate the scheduled maintenance by Google which puts the datastore into read-only mode?

相关标签:
1条回答
  • 2021-02-07 18:53

    I wish there was a checkbox that would make the datastore read-only. This hack seems to do what I need. Put the following in your main handler:

    from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
    from google.appengine.api import apiproxy_stub_map
    
    def make_datastore_readonly():
      """Throw ReadOnlyError on put and delete operations."""
      def hook(service, call, request, response):
        assert(service == 'datastore_v3')
        if call in ('Put', 'Delete'):
          raise CapabilityDisabledError('Datastore is in read-only mode')
      apiproxy_stub_map.apiproxy.GetPreCallHooks().Push('readonly_datastore', hook, 'datastore_v3')
    
    def main():
      make_datastore_readonly()
    

    It was found here: http://groups.google.com/group/google-appengine/msg/51db9d51401715ca

    0 讨论(0)
提交回复
热议问题