python - setting GAE namespace -


this function works fine on interactive console:

from google.appengine.api import namespace_manager google.appengine.ext import db  namespace_manager.set_namespace("some_namespace")  class class(db.model):     c = db.stringproperty()  x = class(c="text") x.put() 

but when login executes namespace_manager.set_namespace(user.namespace) data retrieved , stored in datastore belongs root (empty) namespace.

that raises questions

  1. am setting namespace wrong?
  2. do have set each time before retrieve , store data (that wan't case in guestbook example)
  3. if namespece set on server side how know post/get() belongs namespace?

please dont point me link: https://developers.google.com/appengine/docs/python/multitenancy/multitenancy documentation very...

edit answers question

"set_namespace(namespace) sets namespace current http request."

and guess answer "why guestbook example different" in appengine_config.py.

now question - when logging in user must able read root namespace, appearantly must store user data in root namespace, once logged in , namespace set specific, cookie check function can't access root namespace , causes error.

how around that? (feel talking myself)

you need set namespace within handler function because if set namespace example right under imports part of code cached , wont re-executed every request. same if set in non dynamic portion of code.

so think happens first time code loads there no user , namespace wont change. of course works in interactive console because whole part of code gets exectuted.

# namespace of user when code loads or nothing # , never change long instance namespace_manager.set_namespace(user.namespace)    class yourhandler(webapp2.requesthandler):     def get(self):        # user....        namespace_manager.set_namespace(user.namespace)        # setting namespace here change each request. 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -