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

django-inlinecss crashes when DEBUG = False #35

Open
WhyNotHugo opened this issue Oct 21, 2017 · 4 comments
Open

django-inlinecss crashes when DEBUG = False #35

WhyNotHugo opened this issue Oct 21, 2017 · 4 comments

Comments

@WhyNotHugo
Copy link
Contributor

There's some broken behaviour here that only runs when DEBUG = False.

The condition itself is super dangerous: I only picked this up on CI, but many would have only picked it up on production.

It seems that when not running debug mode:

  • collectstatic is expected to have run. This isn't usually the case when testing/CI/etc.
  • It is assumed that static files are in the local filesystem. This is very often not the case (eg: when using a CDN).

Line 30 crashes because a file is missing. The only way around it it by setting the static storage to a local filesystem storage, and running collectstatic. The former is not viable in production, and I'd rather avoid the latter when running tests locally.

I really don't see any reason to fork depending on the DEBUG setting. It's probably best to always use the staticfiles finder.

An alternative fix, is to actually open the file (rather that extract it's path and assume it's a local path), but this still means collectstatic has to be run on non-production environments.

@AdrienLemaire
Copy link

AdrienLemaire commented Oct 4, 2018

@WhyNotHugo have you solved this issue for your case ?

I knew django-inlinecss was old and apparently unmaintained, but couldn't find another library to cover a .css file code to inline css, and while it works in local with local files, it breaks on staging with GCP storage.

I suppose I'll fork the project and replace

            if settings.DEBUG:
                expanded_path = finders.find(path)
            else:
                expanded_path = staticfiles_storage.path(path)

with

            expanded_path = finders.find(path)

@WhyNotHugo
Copy link
Contributor Author

WhyNotHugo commented Oct 4, 2018

That should work, since it would read the file from the django project itself, rather than from the actual staticfiles storage, right?

Regrettably, I don't think PRs here are receiving any attention though. :(

I only worked around the issue; but have since moved to using whitenoise and have that mirrored by a CDN (which means I do run collectstatic in production now).

@treyhunner
Copy link

@melinath just tried to start using this project today but this seems to be an issue that's causing my tests to fail (my automated tests check my email template output).

@ram-nad
Copy link

ram-nad commented Jan 15, 2020

@WhyNotHugo have you solved this issue for your case ?

I knew django-inlinecss was old and apparently unmaintained, but couldn't find another library to cover a .css file code to inline css, and while it works in local with local files, it breaks on staging with GCP storage.

I suppose I'll fork the project and replace

            if settings.DEBUG:
                expanded_path = finders.find(path)
            else:
                expanded_path = staticfiles_storage.path(path)

with

            expanded_path = finders.find(path)

Adding the following in setting.py updates the Loader and fixes this error.

INLINECSS_CSS_LOADER = "django_inlinecss.css_loaders.StaticfilesFinderCSSLoader"

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

4 participants