Skip to content

Conversation

@wojcikstefan
Copy link
Member

I originally changed the exception name from ConnectionError to MongoEngineConnectionError in
b02904e, inspired by landscape.io's package health report, which argued that ConnectionError is already a built-in exception in Python 3.

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 and call this exception ConnectionFailure.

Note that this is a breaking change and people will need to rename MongoEngineConnectionErrors 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.
https://github.com/kennethreitz/requests/blob/4983a9bde39c6320aa4f3e34e50dac6e263dab6f/requests/exceptions.py#L32
or
https://github.com/andymccurdy/redis-py/blob/0be4d2920684345eb52115c7142c39d65356e7d4/redis/exceptions.py#L8

I originally changed the exception name from `ConnectionError` to
`MongoEngineConnectionError` in
b02904e,
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 (
https://github.com/mongodb/mongo-python-driver/blob/8855a510a80a30268ffd4b90be65fb26929648e2/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.
https://github.com/kennethreitz/requests/blob/4983a9bde39c6320aa4f3e34e50dac6e263dab6f/requests/exceptions.py#L32
or
https://github.com/andymccurdy/redis-py/blob/0be4d2920684345eb52115c7142c39d65356e7d4/redis/exceptions.py#L8
Copy link
Collaborator

@bagerard bagerard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, users that are importing MongoengineConnectionError should see their code break immediately so I believe it's quite safe to change this

@wojcikstefan wojcikstefan merged commit 9170eea into master Jun 30, 2019
@wojcikstefan wojcikstefan deleted the connection-failure-exception branch June 30, 2019 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants