mbr / flask-kvsession

A drop-in replacement for Flask's session handling using server-side sessions.
http://pythonhosted.org/Flask-KVSession/
MIT License
168 stars 53 forks source link

Using SQLAlchemy data stored as binary and wrapped as binary when opened #41

Closed asielen closed 8 years ago

asielen commented 8 years ago

Python 3.5 + MySQL

When data is stored to a session it is pickled and stored as a binary string:

ex:

session["card"] = "'PP000007C|'
# pickled as:
b'\x80\x03}q\x00(X\x06\x00\x00\x00_freshq\x01\x89X\x05\x00\x00\x00cardsq\x02X\n\x00\x00\x00PP000007C|q\x03u.'

When we later try to get the data, it is pulled as a bytes object out of the database and wrapped again as a string:

For example on that same string above it is pulled out of the database as: b"b'\x80\x03}q\x00(X\x06\x00\x00\x00_freshq\x01\x89X\x05\x00\x00\x00cardsq\x02X\n\x00\x00\x00PP000007C|q\x03u.'"

As you can see, the binary string is stored again cast as a binary string.

Relevant files: flask_kvsessioninit.py Line 186:

# save the session, now its no longer new (or modified)
data = self.serialization_method.dumps(dict(session))

# in this case, data == b'\x80\x03}q\x00(X\x06\x00\x00\x00_freshq\x01\x89X\x05\x00\x00\x00cardsq\x02X\n\x00\x00\x00PP000007C|q\x03u.'

asielen commented 8 years ago

Issue seems to be on the database/sqlalchemy end, not in the library