mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #34806 -- Made cached_db session backend resilient to cache write errors.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
This commit is contained in:
@@ -517,6 +517,22 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):
|
||||
with self.assertRaises(InvalidCacheBackendError):
|
||||
self.backend()
|
||||
|
||||
@override_settings(
|
||||
CACHES={"default": {"BACKEND": "cache.failing_cache.CacheClass"}}
|
||||
)
|
||||
def test_cache_set_failure_non_fatal(self):
|
||||
"""Failing to write to the cache does not raise errors."""
|
||||
session = self.backend()
|
||||
session["key"] = "val"
|
||||
|
||||
with self.assertLogs("django.contrib.sessions", "ERROR") as cm:
|
||||
session.save()
|
||||
|
||||
# A proper ERROR log message was recorded.
|
||||
log = cm.records[-1]
|
||||
self.assertEqual(log.message, f"Error saving to cache ({session._cache})")
|
||||
self.assertEqual(str(log.exc_info[1]), "Faked exception saving to cache")
|
||||
|
||||
|
||||
@override_settings(USE_TZ=True)
|
||||
class CacheDBSessionWithTimeZoneTests(CacheDBSessionTests):
|
||||
|
||||
Reference in New Issue
Block a user