1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +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:
Sulabh Katila
2024-02-21 19:51:58 -05:00
committed by GitHub
parent 6feaad9113
commit eceb5e2eea
6 changed files with 57 additions and 5 deletions

View File

@@ -2,12 +2,16 @@
Cached, database-backed sessions.
"""
import logging
from django.conf import settings
from django.contrib.sessions.backends.db import SessionStore as DBStore
from django.core.cache import caches
KEY_PREFIX = "django.contrib.sessions.cached_db"
logger = logging.getLogger("django.contrib.sessions")
class SessionStore(DBStore):
"""
@@ -52,7 +56,10 @@ class SessionStore(DBStore):
def save(self, must_create=False):
super().save(must_create)
self._cache.set(self.cache_key, self._session, self.get_expiry_age())
try:
self._cache.set(self.cache_key, self._session, self.get_expiry_age())
except Exception:
logger.exception("Error saving to cache (%s)", self._cache)
def delete(self, session_key=None):
super().delete(session_key)