Loading django/contrib/staticfiles/management/commands/collectstatic.py +6 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,12 @@ class Command(NoArgsCommand): processor = self.storage.post_process(found_files, dry_run=self.dry_run) for original_path, processed_path, processed in processor: if isinstance(processed, Exception): self.stderr.write("Post-processing '%s' failed!" % original_path) # Add a blank line before the traceback, otherwise it's # too easy to miss the relevant part of the error message. self.stderr.write("") raise processed if processed: self.log("Post-processed '%s' as '%s'" % (original_path, processed_path), level=1) Loading django/contrib/staticfiles/storage.py +4 −1 Original line number Diff line number Diff line Loading @@ -251,7 +251,10 @@ class CachedFilesMixin(object): for patterns in self._patterns.values(): for pattern, template in patterns: converter = self.url_converter(name, template) try: content = pattern.sub(converter, content) except ValueError as exc: yield name, None, exc if hashed_file_exists: self.delete(hashed_name) # then save the processed result Loading tests/staticfiles_tests/project/faulty/faulty.css 0 → 100644 +1 −0 Original line number Diff line number Diff line @import url("missing.css"); tests/staticfiles_tests/tests.py +16 −1 Original line number Diff line number Diff line Loading @@ -244,7 +244,7 @@ class TestCollection(CollectionTestCase, TestDefaults): class TestCollectionClear(CollectionTestCase): """ Test the ``--clear`` option of the ``collectstatic`` managemenet command. Test the ``--clear`` option of the ``collectstatic`` management command. """ def run_collectstatic(self, **kwargs): clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt') Loading Loading @@ -550,6 +550,21 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, self.assertNotIn(b"cached/other.css", content) self.assertIn(b"other.d41d8cd98f00.css", content) @override_settings( STATICFILES_DIRS=(os.path.join(TEST_ROOT, 'project', 'faulty'),), STATICFILES_FINDERS=('django.contrib.staticfiles.finders.FileSystemFinder',), ) def test_post_processing_failure(self): """ Test that post_processing indicates the origin of the error when it fails. Regression test for #18986. """ finders._finders.clear() err = six.StringIO() with self.assertRaises(Exception) as cm: call_command('collectstatic', interactive=False, verbosity=0, stderr=err) self.assertEqual("Post-processing 'faulty.css' failed!\n\n", err.getvalue()) # we set DEBUG to False here since the template tag wouldn't work otherwise @override_settings(**dict(TEST_SETTINGS, Loading Loading
django/contrib/staticfiles/management/commands/collectstatic.py +6 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,12 @@ class Command(NoArgsCommand): processor = self.storage.post_process(found_files, dry_run=self.dry_run) for original_path, processed_path, processed in processor: if isinstance(processed, Exception): self.stderr.write("Post-processing '%s' failed!" % original_path) # Add a blank line before the traceback, otherwise it's # too easy to miss the relevant part of the error message. self.stderr.write("") raise processed if processed: self.log("Post-processed '%s' as '%s'" % (original_path, processed_path), level=1) Loading
django/contrib/staticfiles/storage.py +4 −1 Original line number Diff line number Diff line Loading @@ -251,7 +251,10 @@ class CachedFilesMixin(object): for patterns in self._patterns.values(): for pattern, template in patterns: converter = self.url_converter(name, template) try: content = pattern.sub(converter, content) except ValueError as exc: yield name, None, exc if hashed_file_exists: self.delete(hashed_name) # then save the processed result Loading
tests/staticfiles_tests/project/faulty/faulty.css 0 → 100644 +1 −0 Original line number Diff line number Diff line @import url("missing.css");
tests/staticfiles_tests/tests.py +16 −1 Original line number Diff line number Diff line Loading @@ -244,7 +244,7 @@ class TestCollection(CollectionTestCase, TestDefaults): class TestCollectionClear(CollectionTestCase): """ Test the ``--clear`` option of the ``collectstatic`` managemenet command. Test the ``--clear`` option of the ``collectstatic`` management command. """ def run_collectstatic(self, **kwargs): clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt') Loading Loading @@ -550,6 +550,21 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, self.assertNotIn(b"cached/other.css", content) self.assertIn(b"other.d41d8cd98f00.css", content) @override_settings( STATICFILES_DIRS=(os.path.join(TEST_ROOT, 'project', 'faulty'),), STATICFILES_FINDERS=('django.contrib.staticfiles.finders.FileSystemFinder',), ) def test_post_processing_failure(self): """ Test that post_processing indicates the origin of the error when it fails. Regression test for #18986. """ finders._finders.clear() err = six.StringIO() with self.assertRaises(Exception) as cm: call_command('collectstatic', interactive=False, verbosity=0, stderr=err) self.assertEqual("Post-processing 'faulty.css' failed!\n\n", err.getvalue()) # we set DEBUG to False here since the template tag wouldn't work otherwise @override_settings(**dict(TEST_SETTINGS, Loading