瀏覽代碼

Fixed #30599 -- Prevented ManifestFilesMixin.read_manifest() from silencing errors other than FileNotFoundError.

zeyneloz 5 年之前
父節點
當前提交
955b382600
共有 2 個文件被更改,包括 7 次插入1 次删除
  1. 1 1
      django/contrib/staticfiles/storage.py
  2. 6 0
      tests/staticfiles_tests/test_storage.py

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

@@ -382,7 +382,7 @@ class ManifestFilesMixin(HashedFilesMixin):
         try:
             with self.open(self.manifest_name) as manifest:
                 return manifest.read().decode()
-        except OSError:
+        except FileNotFoundError:
             return None
 
     def load_manifest(self):

+ 6 - 0
tests/staticfiles_tests/test_storage.py

@@ -4,6 +4,7 @@ import sys
 import tempfile
 import unittest
 from io import StringIO
+from unittest import mock
 
 from django.conf import settings
 from django.contrib.staticfiles import finders, storage
@@ -389,6 +390,11 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
         storage.staticfiles_storage.manifest_name = 'does.not.exist.json'
         self.assertIsNone(storage.staticfiles_storage.read_manifest())
 
+    def test_manifest_does_not_ignore_permission_error(self):
+        with mock.patch('builtins.open', side_effect=PermissionError):
+            with self.assertRaises(PermissionError):
+                storage.staticfiles_storage.read_manifest()
+
     def test_loaded_cache(self):
         self.assertNotEqual(storage.staticfiles_storage.hashed_files, {})
         manifest_content = storage.staticfiles_storage.read_manifest()