views:

252

answers:

1

I've recently pushed a Django app live. We built the app in a staging subdomain on the server. When I went live, I copied the files of the staging subdomain to the main site, created a staging database and pointed the old staging site at the new staging database (leaving the new live site pointed at the original database). This is on mod_python under Apache.

I've created unique SESSION_COOKIE_NAME settings for both sites and I've set SESSION_COOKIE_DOMAIN to ".sitename.com" for the live site and None for the staging site.

The problem we're seeing is users in the live admin are making edits that (it appears) are being saved to the staging site. Users are also being logged out of the admin site "randomly" during requests.

Is there something I'm clearly doing wrong here? Should SESSION_COOKIE_DOMAIN be "www.sitename.com" to restrict it since the subdomain is at "staging.sitename.com"? Did I leave behind old session info in the now-live database (I ran ./manage.py clean and deleted all the sessions from the live database before this issue cropped up)?

Thanks

+3  A: 

We ran into this problem in the last few weeks. There were a couple of places where this could overlap.

1) Are you running separate python interpreters? There are a few ways to configure mod_python so that the threads don't step on each other. The key points here are to provide a distinct ServerName (in this case, the domains staging.sitename.com and www.sitename.com), as well as provide a distinct PythonInterpreter configuration setting in your Apache vhosts configuration file.

PythonInterpreter mysite

Relevant Django docs on same-server deployments

2) Are you running a cache backend on the same port? There is a configuration in settings.py that lets you prefix the cached content with several characters to separate staging content from live content. This is implemented with the following configuration in settings.py:

CACHE_MIDDLEWARE_KEY_PREFIX = "STG_"

Another option could be to run on separate filesystem caches for awhile to see if the problem is resolved. In settings.py, try adding

CACHE_BACKEND = 'file:///var/tmp/django_cache'

3) Have you tried deleting all of your .pyc files? Bizarrely, when the above two solutions failed to resolve our issue, we ran a bash command to delete all of the compiled python files (.pyc files) while the server was stopped.

find ./ -type f -name "*.pyc" -exec rm -f {} \;

This would indicate that changes in your deployment were not recompiling for one reason or another.

Hope this helps!

Mike Clarke
Excellent answer!
Van Gale
Tom
Tom