From 0209e4a4a4b64b4dcd05f7ce717c066df0e3116d Mon Sep 17 00:00:00 2001 From: Prashant Mital <5883388+prashantmital@users.noreply.github.com> Date: Wed, 28 Jul 2021 16:01:32 -0700 Subject: [PATCH] PYTHON-2571 Remove NotMasterError (#688) --- doc/changelog.rst | 2 ++ doc/migrate-to-pymongo4.rst | 6 ++++++ pymongo/errors.py | 20 +++----------------- test/test_errors.py | 6 ------ 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index d3462b7bb..5c943407d 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -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 diff --git a/doc/migrate-to-pymongo4.rst b/doc/migrate-to-pymongo4.rst index fa847a83b..b64ada865 100644 --- a/doc/migrate-to-pymongo4.rst +++ b/doc/migrate-to-pymongo4.rst @@ -378,6 +378,12 @@ custom types to BSON, the :class:`~bson.codec_options.TypeCodec` and For more information, see the :doc:`custom type example `. +NotMasterError is removed +------------------------- + +Removed :exc:`~pymongo.errors.NotMasterError`. +Use :exc:`~pymongo.errors.NotPrimaryError` instead. + Removed features with no migration path --------------------------------------- diff --git a/pymongo/errors.py b/pymongo/errors.py index b0bcc3ed1..dd1c244e3 100644 --- a/pymongo/errors.py +++ b/pymongo/errors.py @@ -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): diff --git a/test/test_errors.py b/test/test_errors.py index 6ae8ee69b..aec7bf478 100644 --- a/test/test_errors.py +++ b/test/test_errors.py @@ -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()