0
0
mirror of https://github.com/django/django.git synced 2024-11-29 14:46:18 +01:00

Fixed #26694 -- Made FileBasedCache.get() reraise non-ENOENT IOErrors.

This commit is contained in:
Jon Dufresne 2016-06-01 12:29:24 -07:00 committed by Tim Graham
parent 3db04d4422
commit 779829662d
2 changed files with 14 additions and 2 deletions

View File

@ -40,8 +40,8 @@ class FileBasedCache(BaseCache):
if not self._is_expired(f): if not self._is_expired(f):
return pickle.loads(zlib.decompress(f.read())) return pickle.loads(zlib.decompress(f.read()))
except IOError as e: except IOError as e:
if e.errno == errno.ENOENT: if e.errno != errno.ENOENT:
pass # Cache file doesn't exist. raise
return default return default
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):

12
tests/cache/tests.py vendored
View File

@ -5,6 +5,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import copy import copy
import io
import os import os
import re import re
import shutil import shutil
@ -1261,6 +1262,17 @@ class FileBasedCacheTests(BaseCacheTests, TestCase):
# This fails if not using the highest pickling protocol on Python 2. # This fails if not using the highest pickling protocol on Python 2.
cache.set('unpicklable', UnpicklableType()) cache.set('unpicklable', UnpicklableType())
def test_get_ignores_enoent(self):
cache.set('foo', 'bar')
os.unlink(cache._key_to_file('foo'))
# Returns the default instead of erroring.
self.assertEqual(cache.get('foo', 'baz'), 'baz')
def test_get_does_not_ignore_non_enoent_errno_values(self):
with mock.patch.object(io, 'open', side_effect=IOError):
with self.assertRaises(IOError):
cache.get('foo')
@override_settings(CACHES={ @override_settings(CACHES={
'default': { 'default': {