Fixed #26694 -- Made FileBasedCache.get() reraise non-ENOENT IOErrors.
This commit is contained in:
parent
3db04d4422
commit
779829662d
|
@ -40,8 +40,8 @@ class FileBasedCache(BaseCache):
|
|||
if not self._is_expired(f):
|
||||
return pickle.loads(zlib.decompress(f.read()))
|
||||
except IOError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
pass # Cache file doesn't exist.
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
return default
|
||||
|
||||
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import copy
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
@ -1261,6 +1262,17 @@ class FileBasedCacheTests(BaseCacheTests, TestCase):
|
|||
# This fails if not using the highest pickling protocol on Python 2.
|
||||
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={
|
||||
'default': {
|
||||
|
|
Loading…
Reference in New Issue