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:
parent
3db04d4422
commit
779829662d
4
django/core/cache/backends/filebased.py
vendored
4
django/core/cache/backends/filebased.py
vendored
@ -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):
|
||||
|
12
tests/cache/tests.py
vendored
12
tests/cache/tests.py
vendored
@ -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
Block a user