PYTHON-2571 Remove NotMasterError (#688)

This commit is contained in:
Prashant Mital 2021-07-28 16:01:32 -07:00 committed by GitHub
parent 70a1fec9a2
commit 0209e4a4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 23 deletions

View File

@ -70,6 +70,8 @@ Breaking Changes in 4.0
:meth:`~pymongo.collection.Collection.find`,
:meth:`~pymongo.collection.Collection.find_one`, and
:meth:`~pymongo.cursor.Cursor`.
- Removed :exc:`pymongo.errors.NotMasterError`.
Use :exc:`pymongo.errors.NotPrimaryError` instead.
- The "tls" install extra is no longer necessary or supported and will be
ignored by pip.
- PyMongoCrypt 1.1.0 or later is now required for client side field level

View File

@ -378,6 +378,12 @@ custom types to BSON, the :class:`~bson.codec_options.TypeCodec` and
For more information, see the
:doc:`custom type example <examples/custom_type>`.
NotMasterError is removed
-------------------------
Removed :exc:`~pymongo.errors.NotMasterError`.
Use :exc:`~pymongo.errors.NotPrimaryError` instead.
Removed features with no migration path
---------------------------------------

View File

@ -93,22 +93,7 @@ def _format_detailed_error(message, details):
return message
class NotMasterError(AutoReconnect):
"""**DEPRECATED** - The server responded "not master" or
"node is recovering".
This exception has been deprecated and will be removed in PyMongo 4.0.
Use :exc:`~pymongo.errors.NotPrimaryError` instead.
.. versionchanged:: 3.12
Deprecated. Use :exc:`~pymongo.errors.NotPrimaryError` instead.
"""
def __init__(self, message='', errors=None):
super(NotMasterError, self).__init__(
_format_detailed_error(message, errors), errors=errors)
class NotPrimaryError(NotMasterError):
class NotPrimaryError(AutoReconnect):
"""The server responded "not primary" or "node is recovering".
These errors result from a query, write, or command. The operation failed
@ -124,7 +109,8 @@ class NotPrimaryError(NotMasterError):
.. versionadded:: 3.12
"""
def __init__(self, message='', errors=None):
super(NotPrimaryError, self).__init__(message, errors=errors)
super(NotPrimaryError, self).__init__(
_format_detailed_error(message, errors), errors=errors)
class ServerSelectionTimeoutError(AutoReconnect):

View File

@ -21,7 +21,6 @@ sys.path[0:0] = [""]
from pymongo.errors import (BulkWriteError,
EncryptionError,
NotPrimaryError,
NotMasterError,
OperationFailure)
from test import (PyMongoTestCase,
unittest)
@ -101,11 +100,6 @@ class TestErrors(PyMongoTestCase):
self.assertPyMongoErrorEqual(exc, exc2)
self.assertOperationFailureEqual(cause, exc2.cause)
def test_NotMasterError_catches_NotPrimaryError(self):
with self.assertRaises(NotMasterError) as exc:
raise NotPrimaryError("not primary test", {"errmsg": "error"})
self.assertIn("full error", str(exc.exception))
if __name__ == "__main__":
unittest.main()