PythonでGoogleAppEngineのすべてのDB操作の名前空間を設定しようとしていますが、設定できません。
現在、私のコードは次のようになっています。
""" Set Google namespace """
if user:
namespace = thisUser.namespace
namespace_manager.set_namespace(namespace)
""" End Google namespace """
#Then i have all sorts of classes:
class MainPage(BaseHandler):
def get(self):
#code with DB operations like get and put...
class MainPage2(BaseHandler):
def get(self):
#code with DB operations like get and put...
class MainPage3(BaseHandler):
def get(self):
#code with DB operations like get and put...
app = webapp2.WSGIApplication([ ... ], debug=True, config=webapp2_config)
これに伴う問題は、クラスではすべてのDB操作がデフォルトの名前空間で実行されることです(名前空間が設定されていないかのように)。イベントでは、コードの一番上に名前空間を設定しました。
コードの先頭にも設定している変数「namespace」を出力すると、使用したい名前空間が表示されます。
しかし、Google App Engineは、クラスでコードを実行する前に、どこかで名前空間を空にリセットしているようです。
だから今、どこかに名前空間を設定する良い方法があるかどうか疑問に思っています。
現在、私はすべての「def」で次のように設定しています。
class MainPage(BaseHandler):
def get(self):
namespace_manager.set_namespace(namespace)
#code with DB operations like get and put...
class MainPage(BaseHandler):
def get(self):
namespace_manager.set_namespace(namespace)
#code with DB operations like get and put...
etc...
これは、あまりエレガントなソリューションではありません。