#28055: Staticfiles HashedFilesMixin postprocess optimization
-------------------------------------+-------------------------------------
Reporter: Konrad Lisiczyński | Owner: Konrad
Type: | Lisiczyński
Cleanup/optimization | Status: assigned
Component: contrib.staticfiles | Version: 1.11
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage:
HashedFilesMixin post_process | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Konrad Lisiczyński):
I tried to comment line 304: saved_name = self._save(hashed_name,
content_file).
Unfortunately it is not so easy, as several tests fail now:
{{{
ERROR: test_cache_invalidation
(staticfiles_tests.test_storage.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/test_storage.py",
line 252, in test_cache_invalidation
self.assertEqual(self.hashed_file_path(name), hashed_name)
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/test_storage.py",
line 21, in hashed_file_path
fullpath = test.render_template(test.static_template_snippet(path))
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/cases.py",
line 33, in render_template
return template.render(Context(**kwargs)).strip()
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
176, in render
return self._render(context)
File "/home/konrad/PycharmProjects/django/django/test/utils.py", line
101, in instrumented_test_render
return self.nodelist.render(context)
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
944, in render
bit = node.render_annotated(context)
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
911, in render_annotated
return self.render(context)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
106, in render
url = self.url(context)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
103, in url
return self.handle_simple(path)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
118, in handle_simple
return staticfiles_storage.url(path)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 155, in url
return self._url(self.stored_name, name, force)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 134, in _url
hashed_name = hashed_name_func(*args)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 364, in stored_name
self.hashed_name(name, content=None, filename=intermediate_name)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 94, in hashed_name
raise ValueError("The file '%s' could not be found with %r." %
(filename, self))
ValueError: The file 'cached/styles.bb84a0240107.css' could not be found
with <django.contrib.staticfiles.storage.CachedStaticFilesStorage object
at 0x7f6b90e00978>.
======================================================================
ERROR: test_path_with_querystring
(staticfiles_tests.test_storage.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/test_storage.py",
line 79, in test_path_with_querystring
relpath = self.hashed_file_path("cached/styles.css?spam=eggs")
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/test_storage.py",
line 21, in hashed_file_path
fullpath = test.render_template(test.static_template_snippet(path))
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/cases.py",
line 33, in render_template
return template.render(Context(**kwargs)).strip()
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
176, in render
return self._render(context)
File "/home/konrad/PycharmProjects/django/django/test/utils.py", line
101, in instrumented_test_render
return self.nodelist.render(context)
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
944, in render
bit = node.render_annotated(context)
File "/home/konrad/PycharmProjects/django/django/template/base.py", line
911, in render_annotated
return self.render(context)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
106, in render
url = self.url(context)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
103, in url
return self.handle_simple(path)
File
"/home/konrad/PycharmProjects/django/django/templatetags/static.py", line
118, in handle_simple
return staticfiles_storage.url(path)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 155, in url
return self._url(self.stored_name, name, force)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 134, in _url
hashed_name = hashed_name_func(*args)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 364, in stored_name
self.hashed_name(name, content=None, filename=intermediate_name)
File
"/home/konrad/PycharmProjects/django/django/contrib/staticfiles/storage.py",
line 94, in hashed_name
raise ValueError("The file '%s' could not be found with %r." %
(filename, self))
ValueError: The file 'cached/styles.bb84a0240107.css' could not be found
with <django.contrib.staticfiles.storage.CachedStaticFilesStorage object
at 0x7f6b910014e0>.
======================================================================
FAIL: test_corrupt_intermediate_files
(staticfiles_tests.test_storage.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File
"/home/konrad/PycharmProjects/django/tests/staticfiles_tests/test_storage.py",
line 298, in test_corrupt_intermediate_files
self.hashed_file_path('cached/styles.css')
File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/home/konrad/PycharmProjects/django/django/test/testcases.py",
line 591, in _assert_raises_message_cm
self.assertIn(expected_message, str(cm.exception))
File "/usr/lib/python3.4/unittest/case.py", line 1056, in assertIn
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/lib/python3.4/unittest/case.py", line 642, in fail
raise self.failureException(msg)
AssertionError: "The name 'cached/styles.css' could not be hashed with
<django.contrib.staticfiles.storage.CachedStaticFilesStorage object at
0x7f6b90a03fd0>." not found in "The file 'cached
/styles.bb84a0240107.css' could not be found with
<django.contrib.staticfiles.storage.CachedStaticFilesStorage object at
0x7f6b90a03fd0>."
}}}
This implies, that this line is needed and it is not some kind of
duplicate after all. Maybe we could contact the author of this code so he
or she could provide us some insight why it was done this way and is it
possible to optimize it somehow.
--
Ticket URL: <https://code.djangoproject.com/ticket/28055#comment:7>
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/064.dd82ac5fa6c6f086b1469785ac155684%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.