Permalink
Browse files

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

  • Loading branch information...
1 parent b8e6e1b commit 887f3d3219b9f8192d27314eceee27ab1f89c5cc @adamzap adamzap committed with timgraham Aug 8, 2016
Showing with 8 additions and 1 deletion.
  1. +4 −1 django/contrib/sessions/backends/base.py
  2. +4 −0 tests/sessions_tests/tests.py
@@ -306,7 +306,10 @@ def cycle_key(self):
"""
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
self.create()
self._session_cache = data
@@ -188,6 +188,10 @@ def test_cycle(self):
self.assertNotEqual(self.session.session_key, prev_key)
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):
self.session['a'] = 'b'
self.session.save()

0 comments on commit 887f3d3

Please sign in to comment.