Ticket #29203: patch_cached_session_deleting_session_cookie.diff

File patch_cached_session_deleting_session_cookie.diff, 1.5 KB (added by Kenial Sookyum Lee, 7 years ago)

workaround patch

  • django/contrib/sessions/middleware.py

    diff --git a/django/contrib/sessions/middleware.py b/django/contrib/sessions/middleware.py
    index 7263b6ac2d..75fbc3be53 100644
    a b class SessionMiddleware(MiddlewareMixin):  
    3535            # First check if we need to delete this cookie.
    3636            # The session should be deleted only if the session is entirely empty
    3737            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
    4351            else:
    4452                if accessed:
    4553                    patch_vary_headers(response, ('Cookie',))
Back to Top