bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
517 stars 147 forks source link

Error when loading session from 1.11 on 1.12 #226

Open kotofos opened 1 year ago

kotofos commented 1 year ago

Error when loading session from 1.11 on 1.12 Looks like a problem was introduced in the code handling deserialization of saved sessions. If the previous session was not serialized.

122

https://github.com/bbangert/beaker/commit/8949516ca0ad418ba6ec2deba7b844ccc787b736

Options:

Reproduce

Tested on pyramid==1.10.8 pyramid-beaker==0.8

  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/pyramid/authentication.py", line 1151, in unauthenticated_userid
    return request.session.get(self.userid_key)
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/session.py", line 789, in __getattr__
    return getattr(self._session(), attr)
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/session.py", line 785, in _session
    self.__dict__['_sess'] = session_cls(req, **params)
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/session.py", line 227, in __init__
    self.load()
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/session.py", line 415, in load
    session_data = self._decrypt_data(session_data)
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/session.py", line 372, in _decrypt_data
    data = b64decode(session_data)
  File "/home/kotofos/Documents/slashdb/slashdb_venv39/lib/python3.9/site-packages/beaker/_compat.py", line 37, in b64decode
    return _b64decode(b.encode('ascii'))
AttributeError: 'dict' object has no attribute 'encode'

Workaround

Delete sessions from filesystem or use invalidate_corrupt