1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #26764 -- Fixed Session.cycle_key() crash on unaccessed session.

This commit is contained in:
Adam Zapletal 2016-08-08 12:01:25 -05:00 committed by Tim Graham
parent b8e6e1b43b
commit 887f3d3219
2 changed files with 8 additions and 1 deletions

View File

@ -306,7 +306,10 @@ class SessionBase(object):
""" """
Creates a new session key, while retaining the current session data. Creates a new session key, while retaining the current session data.
""" """
data = self._session_cache try:
data = self._session_cache
except AttributeError:
data = {}
key = self.session_key key = self.session_key
self.create() self.create()
self._session_cache = data self._session_cache = data

View File

@ -188,6 +188,10 @@ class SessionTestsMixin(object):
self.assertNotEqual(self.session.session_key, prev_key) self.assertNotEqual(self.session.session_key, prev_key)
self.assertEqual(list(self.session.items()), prev_data) self.assertEqual(list(self.session.items()), prev_data)
def test_cycle_with_no_session_cache(self):
self.assertFalse(hasattr(self.session, '_session_cache'))
self.session.cycle_key()
def test_save_doesnt_clear_data(self): def test_save_doesnt_clear_data(self):
self.session['a'] = 'b' self.session['a'] = 'b'
self.session.save() self.session.save()