Browse Source

Fixed #32716 -- Fixed ManifestStaticFilesStorage crash when max_post_process_passes is 0.

aryabartar 3 years ago
parent
commit
651e527f9b

+ 1 - 0
AUTHORS

@@ -99,6 +99,7 @@ answer newbie questions, and generally made Django that much better:
     Arthur Koziel <http://arthurkoziel.com>
     Arthur Rio <arthur.rio44@gmail.com>
     Arvis Bickovskis <viestards.lists@gmail.com>
+    Arya Khaligh <bartararya@gmail.com>
     Aryeh Leib Taurog <http://www.aryehleib.com/>
     A S Alam <aalam@users.sf.net>
     Asif Saif Uddin <auvipy@gmail.com>

+ 1 - 0
django/contrib/staticfiles/storage.py

@@ -260,6 +260,7 @@ class HashedFilesMixin:
                 processed_adjustable_paths[name] = (name, hashed_name, processed)
 
         paths = {path: paths[path] for path in adjustable_paths}
+        substitutions = False
 
         for i in range(self.max_post_process_passes):
             substitutions = False

+ 4 - 0
tests/staticfiles_tests/storage.py

@@ -97,3 +97,7 @@ class ExtraPatternsStorage(ManifestStaticFilesStorage):
 class NoneHashStorage(ManifestStaticFilesStorage):
     def file_hash(self, name, content=None):
         return None
+
+
+class NoPostProcessReplacedPathStorage(ManifestStaticFilesStorage):
+    max_post_process_passes = 0

+ 12 - 0
tests/staticfiles_tests/test_storage.py

@@ -463,6 +463,18 @@ class TestCollectionNoneHashStorage(CollectionTestCase):
         self.assertEqual(relpath, 'cached/styles.css')
 
 
+@override_settings(
+    STATICFILES_STORAGE='staticfiles_tests.storage.NoPostProcessReplacedPathStorage'
+)
+class TestCollectionNoPostProcessReplacedPaths(CollectionTestCase):
+    run_collectstatic_in_setUp = False
+
+    def test_collectstatistic_no_post_process_replaced_paths(self):
+        stdout = StringIO()
+        self.run_collectstatic(verbosity=1, stdout=stdout)
+        self.assertIn('post-processed', stdout.getvalue())
+
+
 @override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.SimpleStorage')
 class TestCollectionSimpleStorage(CollectionTestCase):
     hashed_file_path = hashed_file_path