I'm trying to call a python function that makes some queries into my django database from GNU mailman.
When mailman tries to deliver a message, it imports my python script. It later calls a function in my script to modify the message object. The error I'm getting is:
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation \
for more details.
Here's how I'm configuring the settings, at the very top of my file:
from django.core.management import setup_environ
from mysite import settings
setup_environ(settings)
When I run python manage.py syncdb, it seems to create the database fine. Here's my database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django_db', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'root', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Further, I've commented out the entirety of my function such that it now looks like:
def f():
return
So I don't think this has to do with the function call.
Further, I've tested the setup_environ lines in the python console and everything works as expected.
Further, when I restart GNU mailman, I believe it has to load all its scripts, which means it necessarily has to import my file. This means that these "setup_environ" lines run when I restart mailman. And it's fine -- I get no errors.
It's only when GNU mailman tries to deliver a message that I have problems.
So I'm pretty stumped. I do run the mailman restart command as sudo with additional PYTHONPATH and DJANGO_SETTINGS_MODULE environmental variables, but I've manually added to the relevant parts to my sys.path and os.environ dict, which doesn't fix the problem either. Besides, the error doesn't suggest it's a problem with the path or being unable to find the settings module.
The full stack trace is:
Jun 04 12:06:11 2012 (5249) Uncaught runner exception: settings.DATABASES is improperly configured. Please supply the ENGINE val\
ue. Check settings documentation for more details.
Jun 04 12:06:11 2012 (5249) Traceback (most recent call last):
File "/var/lib/mailman/Mailman/Queue/Runner.py", line 100, in _oneloop
msg, msgdata = self._switchboard.dequeue(filebase)
File "/var/lib/mailman/Mailman/Queue/Switchboard.py", line 173, in dequeue
redirect_list(msg, data)
File "/home/ubuntu/djcode/mysite/mysite/apps/mailman/redirect.py", line 32, in redirect_list
File "/home/ubuntu/djcode/mysite/mysite/apps/mailman/redirect.py", line 45, in _get_real_listname
from mysite.apps.common.models import CustomUser
File "/home/ubuntu/djcode/mysite/mysite/apps/common/custom_user_manager.py", line 54, in get
email_object = Email.objects.get(email=kwargs['email'])
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 131, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 361, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 85, in __len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 291, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 763, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 808, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 71, in as_sql
out_cols = self.get_columns(with_col_aliases)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 218, in get_columns
col_aliases)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 306, in get_default_columns
r = '%s.%s' % (qn(alias), qn2(field.column))
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 49, in quote_name_unless_alias
r = self.connection.ops.quote_name(name)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation \
for more details.