Rename MongoEngineConnectionError to ConnectionFailure (#2111)

I originally changed the exception name from `ConnectionError` to
`MongoEngineConnectionError` in
b02904ee75,
inspired by landscape.io's package health report, which argued that
`ConnectionError` is already a built-in exception in Python 3 (which it is:
https://docs.python.org/3/library/exceptions.html#ConnectionError).

I do agree that we shouldn't override built-in exceptions. [0] That said, it’s
silly to add a "MongoEngine" prefix to any class within the `mongoengine`
module (and *especially* to *just one* exception class out of many). I've
decided to do what PyMongo does (
8855a510a8/pymongo/errors.py (L59))
and call this exception `ConnectionFailure`.

Note that this is a breaking change and people will need to rename
`MongoEngineConnectionError`s in their code to `ConnectionFailure`. Moreover,
if they use PyMongo's `ConnectionFailure` for anything, they'll need to take
    extra care to avoid conflicts, e.g. by using:
```
from mongoengine import ConnectionFailure as MongoEngineConnectionFailure
```

[0] Note that some popular packages still overwrite `ConnectionError`, e.g.
4983a9bde3/requests/exceptions.py (L32)
or
0be4d29206/redis/exceptions.py (L8)
This commit is contained in:
Stefan Wójcik
2019-06-30 09:23:32 +02:00
committed by GitHub
parent 2769967e1e
commit 9170eea784
4 changed files with 22 additions and 22 deletions

View File

@@ -4,7 +4,7 @@ from pymongo import ReadPreference
from pymongo import MongoClient
import mongoengine
from mongoengine.connection import MongoEngineConnectionError
from mongoengine.connection import ConnectionFailure
CONN_CLASS = MongoClient
@@ -32,7 +32,7 @@ class ConnectionTest(unittest.TestCase):
host="mongodb://localhost/mongoenginetest?replicaSet=rs",
read_preference=READ_PREF,
)
except MongoEngineConnectionError as e:
except ConnectionFailure as e:
return
if not isinstance(conn, CONN_CLASS):