sebastian-ardila / google-app-engine-django

Automatically exported from code.google.com/p/google-app-engine-django
Apache License 2.0
0 stars 0 forks source link

Allow non-django handlers to mix with django handlers in the same app #191

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare two types of handlers in your app.yaml, one that uses app engine 
django helper and one that does not
2. Call InstallAppengineHelperForDjango('1.2') in your main script of the 
django handler
3. Wait for a new server instance to get started by a request to the 
*non-django* handler
4. Wait for a second request to get served by the django handler

What is the expected output? What do you see instead?

Since the default django could have been loaded by the non-django handler (a 
spurious import, perhaps to use simplejson or something) then App Engine Helper 
cannot declare a custom version.  This is the exception:

<class 'google.appengine.dist._library.UnacceptableVersionError'>: django 1.2 
was requested, but 0.96.4.None is already in use
Traceback (most recent call last):
  File "/base/data/home/apps/chirpradio/1.349632722498257052/main.py", line 29, in <module>
    InstallAppengineHelperForDjango('1.2')
  File "/base/data/home/apps/chirpradio/1.349632722498257052/appengine_django/__init__.py", line 523, in InstallAppengineHelperForDjango
    LoadDjango(version)
  File "/base/data/home/apps/chirpradio/1.349632722498257052/appengine_django/__init__.py", line 156, in LoadDjango
    use_library('django', version)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/dist/_library.py", line 359, in use_library
    InstallLibrary(name, version, explicit=True)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/dist/_library.py", line 312, in InstallLibrary
    CheckInstalledVersion(name, version, explicit=True)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/dist/_library.py", line 245, in CheckInstalledVersion
    (name, desired_version, installed_version))

What version of the product are you using? On what operating system?

For reference, this is how my main handler was loading the system:

from appengine_django import InstallAppengineHelperForDjango
InstallAppengineHelperForDjango('1.2')

Please provide any additional information below.

The default django (0.96) needs to be cleared out of sys.modules for something 
like this to work.  I attached a patch that clears it out right before the call 
to use_library('1.2')

This patch will ensure that anyone who mixes different types of handlers will 
be guaranteed a working django handler.

Original issue reported on code.google.com by kumar.mcmillan on 11 Apr 2011 at 5:39

Attachments:

GoogleCodeExporter commented 9 years ago
As a side note for anyone else running into this: it's pretty hard to get rid 
of all references loaded in memory.  I decided to remove all traces of Django 
in the non-Django request handlers I had

Original comment by kumar.mcmillan on 16 Apr 2011 at 9:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Follow up: clearing out all django imports is not working because [presumably] 
App Engine's own webapp framework is importing Django 0.96 somewhere.  It might 
be impossible to mix a webapp handler with a Google App Engine Helper handler.

Original comment by kumar.mcmillan on 19 Apr 2011 at 8:53

GoogleCodeExporter commented 9 years ago
Not using google-app-engine-django with other handlers is what I've always 
recommended.

I don't know of any way to safely do it, sorry.

The best work-around I'm aware of if you need non-helper handlers in your app 
is to put them in a separate version (which will get a separate appserver) and 
access them through the version specific URLs. Not pretty though.

Original comment by m...@google.com on 20 Aug 2011 at 5:10