-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: 3.7.2
-
Component/s: API, BSON, Error Handling
-
None
-
Environment:Any
When trying to serialise an unsupported object type to bson, the error message that pymongo generates is sometimes very unhelpful.
For example, I was trying to save a document like this:
{
"value": number1 < number2
}
Normally this would result in a bool, which would be fine.
However, this is the error message I get when trying to run this:
InvalidDocument: Cannot encode object: True
You may ask why it cannot serialise a bool.
It turns out that number1 can sometimes be a numpy type. As a result, the type of the comparison is actually `numpy.bool_` instead of a standard python bool.
The error message would be much more helpful if it contained the type() of the object. For example:
InvalidDocument: Cannot encode object of type 'numpy.bool_': True
- duplicates
-
PYTHON-1664 Unable to serialize object in the insert_one query
- Closed