Skip to content

Commit 889d305

Browse files
authored
Fix issue #180 - KeyError when loading deleted session (#199)
Session.load does not properly handle state after .delete and .save was called. This happens when user logs out, but saves session id, and then tries to use it again.
1 parent edb8f52 commit 889d305

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

beaker/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ def load(self):
437437
self.is_new = True
438438

439439
if self.timeout is not None and \
440+
'_accessed_time' in session_data and \
440441
now - session_data['_accessed_time'] > self.timeout:
441442
timed_out = True
442443
else:

tests/test_session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,16 @@ def test_invalidate_invalid_signed_cookie_invalidate_corrupt():
483483
assert "foo" not in dict(session)
484484

485485

486+
def test_load_deleted_from_storage_session__not_loaded():
487+
req = {'cookie': {'beaker.session.id': 123}}
488+
session = Session(req, timeout=1)
489+
490+
session.delete()
491+
session.save()
492+
493+
Session(req, timeout=1)
494+
495+
486496
class TestSaveAccessedTime(unittest.TestCase):
487497
# These tests can't use the memory session type since it seems that loading
488498
# winds up with references to the underlying storage and makes changes to

0 commit comments

Comments
 (0)