#26249: ManifestStaticFilesStorage crashes on absolute URLs
-----------------------------------------------+------------------------
Reporter: aaugustin | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
To reproduce, enable ManifestStaticFilesStorage:
{{{
STATIC_ROOT= '...'
STATIC_URL = '/static/'
STATICFILES_DIRS = ['...']
STATICFILES_STORAGE =
'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
}}}
Create `a.css` in one of `STATICFILES_DIRS` with this content:
{{{
@font-face{font-family:A;src:url(/static/a.woff) format("woff");}
}}}
Create a `a.woff` file next to `a.css`.
Then collectstatic crashes with this stack trace:
{{{
Post-processing 'a.css' failed!
Traceback (most recent call last):
File "/Users/myk/.virtualenvs/project/bin/django-admin", line 11, in
<module>
sys.exit(execute_from_command_line())
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 176, in handle
collected = self.collect()
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 128, in collect
raise processed
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/storage.py", line 245, in post_process
content = pattern.sub(converter, content)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/storage.py", line 184, in converter
hashed_url = self.url(unquote(joined_result), force=True)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/storage.py", line 131, in url
hashed_name = self.stored_name(clean_name)
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/storage.py", line 280, in stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "/Users/myk/.virtualenvs/project/lib/python3.5/site-
packages/django/contrib/staticfiles/storage.py", line 94, in hashed_name
(clean_name, self))
ValueError: The file 'a.css/a.woff' could not be found with
<django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at
0x105a34240>.
}}}
Using `url(./a.woff)` instead of `url(/static/a.woff)` avoids the issue.
It looks like `HashedFilesMixin.url_converter` doesn't handle that case
gracefully, so we end up with `a.css/a.woff` instead of just `a.woff`.
When a URL starts with `STATIC_URL`, perhaps it should strip it?
(I ended up with the `/static/` prefix because I set webpack's
`output.publicPath` to `/static/`. I don't remember why I need it, but it
doesn't make the bug less valid.)
--
Ticket URL: <https://code.djangoproject.com/ticket/26249>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.10d7769a5ccdc758e43820008f41603e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.