I think i finally found the culprit for the error :) It definitely has
something to do with the deferred library. Actually i was able to
squash the bug by importing deferred library in the same file as the
BaseHandler, even though it isnt used in that file. To sum it up.
Imagine you have 2 files main.py and test_app.py
main.py:
class BaseHandler(webapp2.RequestHandler):
def render_response(self):
bla bla
@webapp2.cached_property
def auth(self):
return auth.get_auth()
...
test_app.py:
from main import BaseHandler
from google.appengine.ext import deferred
class TestHandler(BaseHandler)
def get(self)
user = self.auth.get_user_by_session()
deferred.defer(...)
...
This will create the Error, the fix is to also import deferred library
in main.py, even if it isnt used there.. so main.py would look like
main.py:
from google.appengine.ext import deferred
class BaseHandler(webapp2.RequestHandler):
def render_response(self):
bla bla
@webapp2.cached_property
def auth(self):
return auth.get_auth()
...
Hope this helps someone else.. And this totally opens up for the
possibility that other libraries could do the same..
On 8 Jun., 16:48, Guido van Rossum <
gu...@google.com> wrote:
> Do you have a small sample app that reproduces the error?
>
> On Fri, Jun 8, 2012 at 2:42 AM, Jakob Holmelund
>
>
>
>
>
>
>
>
>
> <
jakobholmel...@gmail.com> wrote:
>
> > Hi guys, i really want to get to the bottom of this.
>
> > AssertionError: Request global variable is not set
>
> > I get this error the first time call
>
> > user = self.auth.get_user_by_session()
>
> > after an instance is started. So that means that any user who gets a new instance will run into an error which is not acceptable.
>
> > I have found some earlier threads where this error was produces by importing an app inside a function. I dont think that its the same thing going on here, so if someone has fixed this, please help.
>
> > Im using Python 2.7 and ndb, so i wrap my app with ndb.toplevel like:
>
> > app = ndb.toplevel(webapp2.WSGIApplication(routes.URLS, debug=config.DEBUG, config=config.CONFIG))
>
> > Here is a stack trace of the error
>
> > Request global variable is not set.
> > Traceback (most recent call last):
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 1536, in __call__
> > rv = self.handle_exception(request, response, e)
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 1530, in __call__
> > rv = self.router.dispatch(request, response)
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 1278, in default_dispatcher
> > return route.handler_adapter(request, response)
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 1102, in __call__
> > return handler.dispatch()
> > File "/base/data/home/apps/s~kobstadendev/1.359392875892326983/main.py", line 81, in dispatch
> > webapp2.RequestHandler.dispatch(self)
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 572, in dispatch
> > return self.handle_exception(e, self.app.debug)
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 570, in dispatch
> > return method(*args, **kwargs)
> > File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/ta sklets.py", line 1009, in synctasklet_wrapper
> > return taskletfunc(*args, **kwds).get_result()
> > File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/ta sklets.py", line 322, in get_result
> > self.check_success()
> > File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/ta sklets.py", line 362, in _help_tasklet_along
> > value = gen.send(val)
> > File "/base/data/home/apps/s~kobstadendev/1.359392875892326983/items_ndb/items.p y", line 439, in get
> > user = self.auth.get_user_by_session()
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 726, in __get__
> > value = self.func(obj)
> > File "/base/data/home/apps/s~kobstadendev/1.359392875892326983/main.py", line 88, in auth
> > return auth.get_auth()
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2_extras/auth.py", line 623, in get_auth
> > request = request or webapp2.get_request()
> > File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/web app2.py", line 1720, in get_request