pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
501 stars 239 forks source link

Type Error when using signed cookies with SQLAlchemy session (Python 3) #37

Closed warrenbailey closed 8 years ago

warrenbailey commented 8 years ago

If I configured my Flask session to use SQLAlchemy and signed cookies I end up with a Type Error when the first request hits my application.

This is the configuration I used to enable this functionality:

application.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:////tmp/test.db'"
application.secret_key = "some value"
application.config['SESSION_KEY_PREFIX'] = 'test'
application.config['SESSION_USE_SIGNER'] = True
application.config['SESSION_COOKIE_SECURE'] = True
application.config['SESSION_TYPE'] = 'sqlalchemy'
Session(application)
db = SQLAlchemy(application)
db.create_all()

The problem appears to originate from the itsdangerous library, the signer returns bytes string for use as the sid, this is concatenated to the key prefix (which is a unicode string) and results in the Type error (see screenshot). Also if I don't set the key prefix it fails as it tries to append None.

screen shot 2016-05-17 at 13 50 13