Opened 19 years ago

Closed 15 years ago

#1154 closed defect (wontfix)

SSI from Apache mod_include directive to django fails

Reported by: Brian Ray <bray@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: normal Keywords: mod_python, SSI
Cc: bray@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django will not accept (server content for) an internal Apache request.

In Example:

<!--#include virtual="/Polls/" -->

The result is printed to the browser:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/local/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 165, in handler
    return ModPythonHandler()(req)

  File "/usr/local/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 126, in __call__
    os.environ.update(req.subprocess_env)

  File "/usr/local/lib/python2.4/os.py", line 478, in update
    self[k] = dict[k]

  File "/usr/local/lib/python2.4/os.py", line 463, in __setitem__
    putenv(key, item)

TypeError: putenv() argument 2 must be string, not list 

And the apache logs say:

[Sun Jan 01 22:10:21 2006] [notice] mod_python: (Re)importing module 'django.core.handlers.modpython' 
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython: Traceback (most recent call last):, referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython:   File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n    result = object(req),  referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython:   File "/usr/local/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 165, in handler\n    return ModPythonHandler()(req),  referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython:   File "/usr/local/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 126, in __call__\n    os.environ.update(req.subprocess_env),  referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython:   File "/usr/local/lib/python2.4/os.py", line 478, in update\n    self[k] = dict[k], referer:  referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython:   File "/usr/local/lib/python2.4/os.py", line 463, in __setitem__\n    putenv(key, item), referer: referer: http://127.0.0.1/Test/
[Sun Jan 01 22:10:21 2006] [error] [client 127.0.0.1] PythonHandler django.core.handlers.modpython: TypeError: putenv() argument 2 must be string, not list, referer:  referer: http://127.0.0.1/Test/

Change History (8)

comment:1 by Adrian Holovaty, 19 years ago

Sorry for the slow response on this, Brian...Could you give more details of how to recreate this problem? Do I put the include statement in a non-Django-powered page and point it at a Django-powered URL on the same server, I assume?

comment:2 by Brian Ray <bray@…>, 19 years ago

I just made a .shtml file (with SSI includes turned on) and put that <!--#include virtual="/Polls/" --> inside a static file being called from the same virtual host as my django instance.

What is happening is mp_table then has two keys with "DJANGO_SETTINGS_MODULE". Magically, this becomes a list of values when a copy is made (note "envvalscopy = ") below.

The fix involves not sending a list. Here is a patch which fixes the problem:

Index: /home/printspur/django/django/core/handlers/modpython.py
===================================================================
--- /home/printspur/django/django/core/handlers/modpython.py   (revision 2390)
+++ /home/printspur/django/django/core/handlers/modpython.py   (working copy)
@@ -122,6 +122,11 @@
            
 class ModPythonHandler(BaseHandler):
     def __call__(self, req):
+        for envks,envval in req.subprocess_env.items():
+           envvalscopy = req.subprocess_env[envks]
+           if type(envvalscopy) == list:
+               req.subprocess_env[envks] = envvalscopy[0]
+
         # mod_python fakes the environ, and thus doesn't process SetEnv.  This fixes that
         os.environ.update(req.subprocess_env)

comment:3 by Brian Ray <bray@…>, 19 years ago

Of course if your sure this is the only place this is happening this is much faster:

Index: /home/printspur/django/django/core/handlers/modpython.py
===================================================================
--- /home/printspur/django/django/core/handlers/modpython.py   (revision 2390)
+++ /home/printspur/django/django/core/handlers/modpython.py   (working copy)
@@ -122,6 +122,11 @@

 class ModPythonHandler(BaseHandler):
     def __call__(self, req):
+        if req.subprocess_env.has_key("DJANGO_SETTINGS_MODULE"):
+            dsm = req.subprocess_env["DJANGO_SETTINGS_MODULE"]
+            if type(dsm) == list:
+                req.subprocess_env["DJANGO_SETTINGS_MODULE"] = dsm[0]
+
         # mod_python fakes the environ, and thus doesn't process SetEnv.  This fixes that
         os.environ.update(req.subprocess_env)

comment:4 by anonymous, 19 years ago

More info:

I have set my enviroment from a virtual host with:

SetEnv DJANGO_SETTINGS_MODULE myproject.settings

This may be getting set twice when it's an internal include like the one above.

comment:5 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: newclosed

I'm inclined to leave this as a wontfix, because it's such an edge case.

comment:6 by Adrian Holovaty, 18 years ago

milestone: Version 0.93

Milestone Version 0.93 deleted

in reply to:  description comment:7 by ParisHolley, 15 years ago

Resolution: wontfix
Status: closedreopened

I ran into this issue trying to use templating in django with a php shopping cart so I could wrap the app with the same design as website. This patch should be considered and added to the next release.

comment:8 by Jacob, 15 years ago

Resolution: wontfix
Status: reopenedclosed

This patch has already been marked wontfix by a a core contributor (Adrian). If it really needs further discussion that should take place on django-dev.

Note: See TracTickets for help on using tickets.
Back to Top