-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
ObjectId states that it will allow str or bytes, and this is repeated within the exception text;
https://github.com/mongodb/mongo-python-driver/blob/master/bson/objectid.py#L199
However, this doesn't seem to work in Python 3 and results in an exception.
File "/home/vagrant/.virtualenvs/vagrant/lib/python3.4/site-packages/bson/objectid.py", line 209, in __validate
"not %s" % (text_type._name_, type(oid)))
TypeError: id must be an instance of (bytes, str, ObjectId), not <class 'bytes'>
This is because py3compat only shows `str` as an allowed type, not `bytes`, as seen here;
https://github.com/mongodb/mongo-python-driver/blob/master/bson/py3compat.py
The recommend fix is to alter the py3compat to allow for both str and bytes. If there is someone here who can accept my PR, I'll go ahead and make a patch if needed.