GoogleCloudPlatform / webapp2

webapp2 is a framework for Google App Engine
https://webapp2.readthedocs.org
Other
141 stars 63 forks source link

Importing a WSGIApplication during a request resets self.app on Google App Engine when using webapp2_extras.local #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If you have webapp2_extras.local installed, and import another WSGIApplication 
during a request, the pointer to self.app will get reset by WSGIApplication's 
constructor. Among other things, this points all the routes you access via 
uri_for to the other application.

Please see the attached sample application for a demonstration of the problem.

(We discovered this while working with a helper method we wrote to give you a 
"global" uri_for that will give you access to named routes from all your 
applications.)

It may be that this is "expected behavior" for webapp2_extras.local. We are 
using GAE/python 2.5 so we aren't using multi-threading and therefore don't 
need that feature. But there is no warning that you *shouldn't* use 
webapp2_extras.local with Google App Engine. In fact, the doc for set_globals 
says webapp2_extras.local "can also be used in environments that don't support 
threading."

We have found two ways to fix this problem:

1. Delete local.py from webapp2_extras. If this is the preferred way, I think 
it should be documented.

2. In WSGIApplication.initialize, change

self.app = WSGIApplication.active_instance

to

self.app = WSGIApplication.active_instance._get_current_object()

But this seems like a hack.

Original issue reported on code.google.com by l...@recursion.org on 3 Oct 2011 at 10:20

Attachments: