Open
Description
PyMongo does not seem to like LazyProxy
objects passed in a query (and most likely in all other places where a dict
that will later be serialized to BSON is required).
The bug, in action:
>>> from pymongo import MongoClient
>>> from lazify import LazyProxy
>>> collection = MongoClient().database.collection
>>> collection.find_one({"test": LazyProxy(list)})
... stacktrace ...
InvalidDocument: Cannot encode object: <lazify.LazyProxy object at 0x7f7daa50d990>
>>>
But surprisingly, it does not happen when the LazyProxy.value
is a dict
:
>>> # works just as expected (returns nothings)
>>> collection.find_one({"test": LazyProxy(dict)})
>>>
Also, it's worth noting that the pure-Python version of PyMongo's bson
works just as expected:
>>> import sys
>>> sys.modules["bson._cbson"] = None
>>> from pymongo import MongoClient
>>> from lazify import LazyProxy
>>> collection = MongoClient().database.collection
>>> collection = MongoClient().database.collection
>>> collection.find_one({"test": LazyProxy(list)})
>>>
The issue is most likely an incompatible way of checking the query contents type somewhere in pymongo/bson/_cbsonmodule.c
.
Versions in place:
Lazify==0.4.0
pymongo==3.7.1
Metadata
Metadata
Assignees
Labels
No labels