﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21486	Backwards incompatible change in 1.6: accessing Apache mod_wsgi environment variables	Jon Dufresne	nobody	"After upgrading from 1.5 to 1.6, my Django application running on Apache with mod_wsgi was unable to access environment variables set by Apache using `SetEnv` and `SetEnvIf`. Using Django 1.5, I was able to access this using the following wsgi.py (edited for brevity):

{{{
import os

from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

def application(environ, start_response):
    os.environ['MY_SETTING'] = environ['MY_SETTING']
    return _application(environ, start_response)
}}}

Then, in settings.py, I would access `MY_SETTING` using `os.environ['MY_SETTING']`. After upgrading, I had to change the file to the following:

{{{
import os

_application = None

def application(environ, start_response):
    os.environ['MY_SETTING'] = environ['MY_SETTING']
    global _application
    if _application is None:
        from django.core.wsgi import get_wsgi_application
        _application = get_wsgi_application()
    return _application(environ, start_response)
}}}

It appears that importing (and callling?) `get_wsgi_application()` kicks off a chain of imports that will eventually import `settings.py`. But, as the OS environment variables aren't set yet, settings.py can't access these environment variables properly.

I am not sure if this is considered a bug, but the backwards incompatible change certainly surprised me. If there is a better way to approach this same problem, I'd be happy to hear it."	Bug	closed	Core (Other)	1.6	Release blocker	fixed			Accepted	0	0	0	0	0	0
