Open WhyNotHugo opened 7 years ago
@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)
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).
@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).
@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"
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.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 meanscollectstatic
has to be run on non-production environments.