Skip to content
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

'Settings' object has no attribute 'COMPRESSORS' #1207

Open
abhishek-choudhury-callhub opened this issue Oct 13, 2023 · 8 comments
Open

'Settings' object has no attribute 'COMPRESSORS' #1207

abhishek-choudhury-callhub opened this issue Oct 13, 2023 · 8 comments

Comments

@abhishek-choudhury-callhub

I followed the remote storages documentation and set all the settings mentioned.

I already have the quickstart settings, but I'm unsure why django_compressor is not working.

I've reviewed all the required settings and reinstalled the packages, but I need to figure out what I'm missing.

Here are my versions:

Django==4.0.2
django-storages==1.14.2
django-compressor==4.4
@estromenko
Copy link

Facing the same issue with Django==3.2.*

@carltongibson
Copy link
Contributor

I don't suppose either of you could paste (at the relevant part) of a stack trace could you please?

@estromenko
Copy link

Sorry for late answer. Just returned to test this package again.

Seems like the issue is not in this package (maybe appconf?).

  File "/my/project/path/.venv/lib/python3.11/site-packages/compressor/management/commands/compress.py", line 370, in handle
    self.handle_inner(**options)
  File "/my/project/path/.venv/lib/python3.11/site-packages/compressor/management/commands/compress.py", line 395, in handle_inner
    offline_manifest, block_count, results = self.compress(
                                             ^^^^^^^^^^^^^^
  File "/my/project/path/.venv/lib/python3.11/site-packages/compressor/management/commands/compress.py", line 200, in compress
    contexts = settings.COMPRESS_OFFLINE_CONTEXT
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/my/project/path/.venv/lib/python3.11/site-packages/django/conf/__init__.py", line 83, in __getattr__
    val = getattr(self._wrapped, name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Settings' object has no attribute 'COMPRESS_OFFLINE_CONTEXT'

If I add COMPRESS_OFFLINE_CONTEXT to the settings, another error will appear:

CommandError: An error occurred during rendering linked/main/index.html: 'Settings' object has no attribute 'COMPRESS_DEBUG_TOGGLE'

... and so on.

@cclauss
Copy link
Contributor

cclauss commented Jan 19, 2024

Do we need to add COMPRESS_OFFLINE_CONTEXT to the installation docs mentioned in the original post?
Or should the code above be modified to gracefully deal with COMPRESS_OFFLINE_CONTEXT not being set?

@carltongibson
Copy link
Contributor

Are we even sure that compressor was installed correctly? (Do we have a reproduce?)

@diox
Copy link
Member

diox commented Jan 19, 2024

Compressor handles that setting (or others) not being set.

The typical issue that can happen is that the settings file has imports causing django to start initializing the apps before the settings are ready.

@g-nie
Copy link

g-nie commented Jan 26, 2024

I just hit this as well and I spent some time trying to figure out what's going on. In my case, compressor doesn't play well with django-configurations. At least when I call configurations.setup(), the compressor settings become broken.
Here's a barebones configurations + compressor (+celery) project that illustrates the issue.
This is the commit (e509c46) that introduces the problem. I do the configurations.setup() in celery.py which is what the docs suggest.
My guess would be that django-configurations clashes with the django-appconf settings that compressor uses.
Hope this helps a bit and do let me know if you need any more info here ✨

@carltongibson
Copy link
Contributor

Looks like jazzband/django-configurations#167 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants