django-compressor/django-appconf

Error when used with django admin autodiscover

peterbrook opened this issue · 4 comments

I see an error when celery_haystack is used with the django admin enabled, but I am filing it here because the error is specifically that the settings added by django-appconf aren't actually available on the settings object imported by "from django.conf import settings".

I am still trying to debug exactly what the issue is, but I see the following behavior when I have:
from django.contrib import admin
admin.autodiscover()
in my settings.py file and I try "python mange.py shell" (thus triggering the import of settings)

For reference, I am monitoring the settings object that is being written to by django/conf/init.py(82)setattr() and I am using:
Django==1.4.3
celery-haystack==0.7.2
-e git+https://github.com/toastdriven/django-haystack.git@2542426da5d75de458ec1c18f511648a328d62c6#egg=django_haystack-dev
django-appconf==0.6

I see that an initial settings object A is written to until the SETTINGS_MODULE environment var is read, at which point another settings object B is written to until the final celery haystack appconf setting (CELERY_HAYSTACK_COMMAND_APPS) is written, at which point the next call to setattr writes to object A again.

If I remove the call to admin.autodiscover() I see that A is written to until SETTINGS_MODULE, then B is written to, then the settings in B are written to A, then the celery haystack appconf settings are written to A.

If I remove the "from django.contrib import admin" line, I see everything written to A directly and everything works perfectly.

@peterbrook - did you find any resolution to this problem? I have a similar issue.

@Erve1879 yes, unfortunately my solution was to simply stop using the django admin interface (and thus remove the call to from django.contrib import admin) :/

Thanks @peterbrook - in the interests of time-saving and deadlines, unfortunately my solution was to stop using celery-haystack (which requires django-appconf and therefore seemed to be suffering from the same issues) altogether.

I'm going to assume this is a timing issue to do with when settings are loaded.

... I see the following behavior when I have:
from django.contrib import admin
admin.autodiscover()
in my settings.py file ...

settings.py isn't a good place for logic that does things. Move this to urls.py (or such)

Make sure your app's settings are loaded. A good place to do this (now) is in Django's AppConf's ready handler.