#21080: collectstatic post-processing fails for references inside comments
-------------------------------------+-------------------------------------
Reporter: shreyas@… | Owner: Tomáš
| Zigo
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by SebastiaanZ):
I noticed that the behavior got worse in Django 4.2.0b1 compared to
pre-4.2 versions.
Let's say you have a javascript file with these contents (minimized
exampled):
{{{
function return_text(text_one, text_two) {
return `${text_one} ${text_two}`;
}
class MyClass {
render(){
return return_text("import App from './App.vue'", 'import { Component
} from "@org/components/loader";');
}
}
}}}
The "import" statements here are part of strings, not actually executable
JavaScript code. In the original snippet, they're part of a component that
shows information on how to use the component library and, as such,
contains strings with imports as part of the documentation.
In Django 3.2.x, 4.0.x, 4.1.x, running `collectstatic` works fine.
However, in the new beta, you get an error:
{{{
(django-42-collectstatic-bug) D:\playground\django-42-collectstatic-
bug>python manage.py collectstatic --clear --no-input -v 0
Post-processing 'example.js' failed!
Traceback (most recent call last):
File "D:\playground\django-42-collectstatic-bug\manage.py", line 22, in
<module>
main()
File "D:\playground\django-42-collectstatic-bug\manage.py", line 18, in
main
execute_from_command_line(sys.argv)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\core\management\__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\management\commands\collectstatic.py",
line 209, in handle
collected = self.collect()
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\management\commands\collectstatic.py",
line 154, in collect
raise processed
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\storage.py", line 364, in
_post_process
content = pattern.sub(converter, content)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\storage.py", line 241, in converter
hashed_url = self._url(
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\storage.py", line 174, in _url
hashed_name = hashed_name_func(*args)
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\storage.py", line 414, in _stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "D:\virtualenvs\django-42-collectstatic-bug\lib\site-
packages\django\contrib\staticfiles\storage.py", line 135, in hashed_name
raise ValueError(
ValueError: The file 'App.vue'", 'import { Component } from
"@org/components/loader' could not be found with
<django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at
0x00000229D19679D0>.
}}}
Unfortunately, this a third-party dependency that we don't control. This
means that we'd have to disable the manifest-backed static file storage
completely in order to continue using this dependency (that we can't
really get rid of), unless I've overlooked an option to disable import
errors for specific files.
--
Ticket URL: <https://code.djangoproject.com/ticket/21080#comment:26>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070186db555b5a-d303282c-aac2-466e-bede-0e14fe277c9e-000000%40eu-central-1.amazonses.com.