New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError at / 'Settings' object has no attribute 'COMPRESS_JS_COMPRESSOR' #333
Comments
If you launch a shell, do you have access to both settings.COMPRESS_DEBUG_TOGGLE and settings.COMPRESS_JS_COMPRESSOR ? |
i can import settings.COMPRESS_DEBUG_TOGGLE in shell, but not settings.COMPRESS_JS_COMPRESSOR.
Last night i tried to override COMPRESS_JS_COMPRESSOR & COMPRESS_CSS_COMPRESSOR in base settings, then it gave me this error:
i think that there is some problem with settings not importing properly, because it is the next setting in compressor configuration? |
Here is how the default settings are set:
I have no idea why it's not happening in your case :( The only thing I can suggest right now is to try adding some debugging to the relevant files in compressor and appconf to see what's going on, and/or make public a reduced mini-project exhibiting this behaviour. |
I'm seeing a similar issue when I run unit tests and use the @override_settings decorator. When I do this there is a local settings context which loads the project's default settings. Because compressor adds its settings by modifying the local cache of django.conf.settings the compressor settings aren't in the local settings context for the unit test. Maybe the solution is to change the way the django_compressor adds it's default settings? |
@evanreiser : I haven't been able to reproduce this myself. Can you provide a patch adding a testcase that fails with override_settings ? Thanks. |
When i look at django.conf.settings outside of the class being modified by the overrides_settings decorator, all the COMPRESSOR settings appear correctly. However once inside the class with the decorator, None fo the COMPRESSOR settings are set (while other settings found in settings.py all exist). I believe this is because appconf is modifying the original settings instance. I'll create a patch + testcase if i have some free time. |
same here ... django 1.4.1 'Settings' object has no attribute 'COMPRESS_DEBUG_TOGGLE' I do have 'compressor' in INSTALLED_APPS installed compress with pip install django_compress, added i to the installed apps and static file finders, and - when adding to the template - it throws this error |
@migajek (and others) If you are able to reproduce, please, please publish a small app and/or project exhibiting the issue (with steps to reproduce in case it's not obvious). Or a proper unit test. I've wrote unit tests against both django-compressor and django-appconf playing with the settings in various ways and did not manage to reproduce the issue. Obviously I'm missing something, it'd be great if one of you could help here. There is very little we can do if we can't reproduce it :( |
I have two projects that i used compressor so far, one of which is django-skel based, and it works like a charm both locally and on Heroku. The other project is on Amazon AWS, and that one works perfect locally, but when deployed, gives me this error. I don't know if i can reproduce the issue with a simple project because of the complexity of the projects & different settings for local & remote, but here is my remote settings, which might help? By the way, we get the error message both with & without Django S3 Folder Storage: from settings.base import *
import djcelery
DEBUG = False
TEMPLATE_DEBUG = DEBUG
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)),
)
# Add django-s3-folder-storage to INSTALLED_APPS
INSTALLED_APPS += (
's3_folder_storage',
)
########## AWS CONFIGURATION
AWS_ACCESS_KEY_ID = '*******************************'
AWS_SECRET_ACCESS_KEY = '************************************************'
AWS_STORAGE_BUCKET_NAME = 'bucket_name'
AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = False
AWS_AUTO_CREATE_BUCKET = True
AWS_QUERYSTRING_AUTH = False
# AWS cache settings, don't change unless you know what you're doing:
AWS_EXPIREY = 60 * 60 * 24 * 7
AWS_HEADERS = {
'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY, AWS_EXPIREY)
}
########## END AWS CONFIGURATION
########## CELERY CONFIGURATION
djcelery.setup_loader()
BROKER_TRANSPORT = 'sqs'
BROKER_TRANSPORT_OPTIONS = {
'region': 'us-east-1',
}
BROKER_USER = AWS_ACCESS_KEY_ID
BROKER_PASSWORD = AWS_SECRET_ACCESS_KEY
########## END CELERY CONFIGURATION
########## S3 FOLDER STORAGE CONFIGURATION
DEFAULT_FILE_STORAGE = 's3_folder_storage.s3.DefaultStorage'
DEFAULT_S3_PATH = "media"
# DEFAULT_S3_PATH = "/"
#
STATICFILES_STORAGE = 's3_folder_storage.s3.StaticStorage'
STATIC_S3_PATH = "static"
MEDIA_ROOT = '/%s/' % DEFAULT_S3_PATH
# MEDIA_ROOT = '/'
#
MEDIA_URL = '//%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME
# MEDIA_URL = '//%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
#
STATIC_ROOT = "/%s/" % STATIC_S3_PATH
STATIC_URL = '//%s.s3.amazonaws.com/static/' % AWS_STORAGE_BUCKET_NAME
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
########## END S3 FOLDER STORAGE CONFIGURATION
# THUMBNAIL_STORAGE defaults to DEFAULT_FILE_STORAGE
THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE
########## COMPRESSION CONFIGURATION
# COMPRESS_ENABLED = True
# Default : the opposite of DEBUG
# see https://github.com/jezdez/django_compressor/issues/226
COMPRESS_OUTPUT_DIR = 'STATIC_CACHE'
# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
COMPRESS_OFFLINE = False
# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
COMPRESS_STORAGE = DEFAULT_FILE_STORAGE
# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
COMPRESS_CSS_FILTERS += [
'compressor.filters.cssmin.CSSMinFilter',
]
# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
COMPRESS_JS_FILTERS += [
'compressor.filters.jsmin.JSMinFilter',
]
COMPRESS_DEBUG_TOGGLE = 'nocompress'
########## END COMPRESSION CONFIGURATION |
I have the same issue. Locally with django's runserver everything works. When deployed with gunicorn/nginx, it breaks with the same errors the other people described. I did a pip freeze in my local machine and installed exactly the same version of all the libraries used. I managed to make it work by installing django-compressor==1.1.2, so maybe there is a commit between 1.1.2 and 1.2 that changed something? |
We're also getting this while using using thet @override_settings decorator. Here's the full stacktrace:
|
More configuration info about our use case: We run our tests with a custom manage.py that looks like this: #!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
if len(sys.argv) > 1 and (sys.argv[1] == 'test' or sys.argv[1] == 'testserver'):
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings")
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv) test_settings.py starts with the line:
... and then all the differences between testing and dev are listed. No compression settings, it's off in settings.py. WORKAROUND: Add these line to the end of test_settings.py:
|
I ran into the same problem, and found an ugly workaround that seems to solve it. Add the following to the bottom of your settings file:
|
For what it's worth, I was able to reproduce this by importing something from compressor in my settings.py. In my case, it was:
but I've tried with a few other compressor imports with the same result. I believe it's something along the lines of a circular import, and the real error is getting swallowed somewhere. |
@bhagany This could be the case for me too. I have a custom path in my COMPRESS_CSS_FILTERS setting, that in turn imports |
Same problem. @ishirav's workaround worked for me. Thanks! @changetip 1 coffee |
Hi @ishirav, @gorillamania sent you a Bitcoin tip worth 1 coffee (2.295 mBTC/$1.50), ➔ collect it at ChangeTip.com. |
Had the same problem using django-avatar (which also use django-appconf) and @ishirav (slightly modified) workaround worked for me too ! Seems to be a django-appconf issue to me. |
I got this problem too. It was caused by having DJANGO_SETTINGS_MODULE set to a local settings file (I have separate dev and prod settings files). The appconf app assumes its 'django.conf.settings', and this causes the problem. appconf needs to check environment vars for the settings module, which it does not as of v0.6... |
Same problem here. My PR above resolves the problem for me but unfortunately does not pass Travis tests... |
I believe I have found the root cause. The issue is that loading settings can be reentrant, so that LazySettings._setup gets called twice. This means that Here is a log -- I modified Django to print entry and exit of LazySettings._setup, Settings.init (including object ID), as well as AppConfMetaClass setting default and configured values. You can set that Settings.init imports the underlying settings module, which in my case imports waffle -- and waffle then refers to django.core.cache, which requires settings, starting the LazySettings._setup path again. It loads successfully, but the Personally I think re-loading settings is an antipattern, but it's also pretty common, since loading settings loads INSTALLED_APPS models.py, which generally pulls in most of the codebase. I'm unclear on a clean fix here. It seems like the "right" place to fix this would be Django, but that doesn't help any projects running on less than django+1. It also seems likely that with 1.7's app loading rework, this may no longer be an issue. (I'm on 1.6 presently, upgrading to 1.7 soon.) I do wonder why compressor doesn't internally refer to AppConf rather than django.conf.settings. For now, I think AppConf should issue a warning when, after loading, it notices that django.conf.settings._wrapped is not the object that AppConf._meta.holder was. Do you maintain AppConf, or is that effectively dead now that it's incorporated into 1.7?
|
FYI, I encountered the problem with Django 1.8b1. |
@nferrari Can you confirm that your LazySettings._setup is being called twice? |
I encountered a similar problem when I tried to use reverse in my settings file. first I got an error saying COMPRESS_DEBUG_TOGGLE did not exist. after adding that attribue, I got another error saying that COMPRESS_JS_COMPRESSOR did not exist. The problem went away when I used reverse_lazy |
If I'm following this right, if this is an issue (rather than a programming error — trying to do things in settings at import time) then it's an issue with AppConf, and not compressor. The relevant location seems to be django-compressor/django-appconf#13. For sanity's sake, and to concentrate the chances of getting a resolution, we should close this and point all discussion there. |
Closing this as per my last comment: it's an AppConf issue. If anyone can help reproduce, please comment on be django-compressor/django-appconf#13 |
i put COMPRESS_DEBUG_TOGGLE = 'blahblah' to my production settings, and now i got:
and points me to this line in my template:
here is my production settings:
any suggestions?
(edit by @diox : original bug report info: #173 (comment) )
The text was updated successfully, but these errors were encountered: