Djongo NotImplementedError: Database objects do not implement truth value testing or bool()

To address the original error:

NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None

This was an intentional minor breaking change we made in PyMongo 4.0 described here:

Database.__bool__ raises NotImplementedError¶
Database now raises an error upon evaluating as a Boolean. Code like this:

if database:
Can be changed to this:

if database is not None:
You must now explicitly compare with None.

https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#database-bool-raises-notimplementederror

The full trackback of the exception will show which line needs to be changed.

2 Likes