Search code examples
djangodjango-southgunicorn

Gunicorn and Django South incompatibility?


I tried installing and using gunicorn for my Django website, but I am running into this error:

$ python manage.py run_gunicorn
2012-12-19 01:46:50 [6877] [INFO] Starting gunicorn 0.16.1
2012-12-19 01:46:50 [6877] [INFO] Listening at: http://127.0.0.1:8000 (6877)
2012-12-19 01:46:50 [6877] [INFO] Using worker: sync
2012-12-19 01:46:50 [6878] [INFO] Booting worker with pid: 6878
2012-12-19 01:46:51 [6878] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 134, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 116, in make_command_wsgi_application
    return AdminMediaHandler(make_wsgi_application(), admin_mediapath)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
    if get_validation_errors(s):
  File "... project folder .../venv/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "... project folder .../venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "... project folder .../venv/lib/python2.7/site-packages/south/models.py", line 2, in <module>
    from south.db import DEFAULT_DB_ALIAS
  File "... project folder .../venv/lib/python2.7/site-packages/south/db/__init__.py", line 81, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
Traceback (most recent call last):
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 134, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 116, in make_command_wsgi_application
    return AdminMediaHandler(make_wsgi_application(), admin_mediapath)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
    if get_validation_errors(s):
  File "... project folder .../venv/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "... project folder .../venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "... project folder .../venv/lib/python2.7/site-packages/south/models.py", line 2, in <module>
    from south.db import DEFAULT_DB_ALIAS
  File "... project folder .../venv/lib/python2.7/site-packages/south/db/__init__.py", line 81, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
2012-12-19 01:46:51 [6878] [INFO] Worker exiting (pid: 6878)
2012-12-19 01:46:51 [6877] [INFO] Shutting down: Master
2012-12-19 01:46:51 [6877] [INFO] Reason: Worker failed to boot.

I found this question which has a similar error, but my DATABASES dict inside settings.py seems correct:

DATABASES = {
    'default': {
        'ENGINE': 'postgresql_psycopg2',
        ...
    }
}

I've put gunicorn into my INSTALLED_APPS. runserver works just fine. south seems so work fine by itself as well.

I managed to get gunicorn working by commenting out south in my INSTALLED_APPS. I guess that can do for when I deploy to production. What is happening?

(For what it's worth, I'm using Django 1.3.2)


Solution

  • Try to use the full path for database backend:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            ...
        }
    }