diff --git a/django/contrib/sessions/middleware.py b/django/contrib/sessions/middleware.py
index 7263b6ac2d..75fbc3be53 100644
a
|
b
|
class SessionMiddleware(MiddlewareMixin):
|
35 | 35 | # First check if we need to delete this cookie. |
36 | 36 | # The session should be deleted only if the session is entirely empty |
37 | 37 | if settings.SESSION_COOKIE_NAME in request.COOKIES and empty: |
38 | | response.delete_cookie( |
39 | | settings.SESSION_COOKIE_NAME, |
40 | | path=settings.SESSION_COOKIE_PATH, |
41 | | domain=settings.SESSION_COOKIE_DOMAIN, |
42 | | ) |
| 38 | try: |
| 39 | # This condition is to check out cache backend is available: |
| 40 | # If cache backend is not available (eg. failover), |
| 41 | # request.session.cache_key raises a connection timeout |
| 42 | # exception, so it doesn't delete a session cookie. |
| 43 | if request.session.cache_key: |
| 44 | response.delete_cookie( |
| 45 | settings.SESSION_COOKIE_NAME, |
| 46 | path=settings.SESSION_COOKIE_PATH, |
| 47 | domain=settings.SESSION_COOKIE_DOMAIN, |
| 48 | ) |
| 49 | except: |
| 50 | pass |
43 | 51 | else: |
44 | 52 | if accessed: |
45 | 53 | patch_vary_headers(response, ('Cookie',)) |