From 955b382600e4626265cc20e5773bdbcfd01fc4af Mon Sep 17 00:00:00 2001 From: zeyneloz Date: Thu, 1 Aug 2019 16:42:58 +0200 Subject: [PATCH] Fixed #30599 -- Prevented ManifestFilesMixin.read_manifest() from silencing errors other than FileNotFoundError. --- django/contrib/staticfiles/storage.py | 2 +- tests/staticfiles_tests/test_storage.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index a021bf46c5..607c11b7d6 100644 --- a/django/contrib/staticfiles/storage.py +++ b/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): diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 59ed734704..93bd60446a 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/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()