﻿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
18518	wsgi.py does not overwrite DJANGO_SETTINGS_MODULE in apache prefork	schaefer@…	nobody	"The wsgi.py Django WSGI application shipped with Django 1.4 contains the following piece of code:

{{{
os.environ.setdefault(""DJANGO_SETTINGS_MODULE"", ""{{ project_name }}.settings"")
}}}

(Obviously adapted to the respective project)

Using setdefault() here is wrong. When using a preforked Apache, different WSGI-application can be run consecutively in the same process. If they use different setting modules, the second application will not overwrite the settings module of the first, resulting in the wrong Django application to be shown.

== Reproduction ==

- Create two Django projects
- Host each of them on a different virtual host
- Reload one a number of times to ""seed"" the processes
- Reload the other one. Notice that (randomly) it shows the *first* project instead of the second

== Fix ==

Replace the aforementioned line with the following:

{{{
os.environ[""DJANGO_SETTINGS_MODULE""] = ""{{ project_name }}.settings""
}}}

There is no reason to try and avoid overwriting the environment variable."	Bug	closed	Uncategorized	1.4	Normal	fixed		schaefer@… Graham Dumpleton leho@… benjaoming@…	Design decision needed	0	0	0	0	0	0
