You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use binary_type in MongoDBStore.__getitem__ for Python 2 only (#401)
* Drop binary_type cast in MongoDBStore.__getitem__
* Coerce PyMongo values to `binary_type` on Python 2
On both Python 2 and Python 3, PyMongo converts `binary_type` (i.e.
`bytes`) to BSON type 5 (Binary data) with subtype 0 to store in the
MongoDB instance. When reading that data back out, PyMongo handles BSON
type 5 (Binary data) with subtype 0 differently depending on the Python
version.
On Python 2, it creates a `bson.Binary` instance with the data. Normally
we would coerce this to a `bytes` object using `ensure_bytes`. However
that fails as `bson.Binary` is a subclass of `bytes`. So instead we
explicitly force it to `bytes` (i.e. `binary_type`). On Python 3,
PyMongo automatically converts the data to `bytes`. Thus we don't need
to do anything there.
ref: http://api.mongodb.com/python/current/python3.html#id3
ref: http://api.mongodb.com/python/current/api/bson/binary.html#bson.binary.Binary
0 commit comments