mongoengine: Incompatibilities with pymongo 4.0

There is a breaking change in pymongo 4.0 that was released very recently

It fails whenever we save an instance right now

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.8/site-packages/mongoengine/document.py:407: in save
    self.ensure_indexes()
/usr/local/lib/python3.8/site-packages/mongoengine/document.py:897: in ensure_indexes
    collection = cls._get_collection()
/usr/local/lib/python3.8/site-packages/mongoengine/document.py:220: in _get_collection
    cls.ensure_indexes()
/usr/local/lib/python3.8/site-packages/mongoengine/document.py:900: in ensure_indexes
    if not collection.is_mongos and collection.read_preference > 1:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = Collection(Database(MongoClient(host=['mongo:27017'], document_class=dict, tz_aware=False, connect=True, read_preference=Primary()), 'cpreview_test'), 'test_document.is_mongos')
    def __bool__(self):
>       raise NotImplementedError("Collection objects do not implement truth "
                                  "value testing or bool(). Please compare "
                                  "with None instead: collection is not None")
E       NotImplementedError: Collection objects do not implement truth value testing or bool(). Please compare with None instead: collection is not None
/usr/local/lib/python3.8/site-packages/pymongo/collection.py:300: NotImplementedError

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Just merged @terencehonles PR, if some of you could test their code against the latest master and provide a feedback, that’d be appreciated. I’ll wait a few days before creating a release

Any help is welcome, feel free to branch out the current state of this PR #2600 and help on any of the error, then open another PR. There are a lot of failures but not so much distinct errors

@bagerard done in #2614

I’m still getting the same error, can you guys please mention what exactly needs to change?