From 753356a7233a79a67fe87a9848c4dcc0d0bdbcfd Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Fri, 19 Dec 2014 16:31:08 -0500 Subject: [PATCH] PYTHON-807 Deprecate Database.error() and related methods. --- doc/changelog.rst | 4 +++ pymongo/database.py | 74 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index e30e428d0..7a49dfcf3 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -30,6 +30,10 @@ Highlights include: - :meth:`~pymongo.mongo_client.MongoClient.in_request` - :meth:`~pymongo.mongo_client.MongoClient.end_request` - :meth:`~pymongo.mongo_client.MongoClient.copy_database` + - :meth:`~pymongo.database.Database.error` + - :meth:`~pymongo.database.Database.last_status` + - :meth:`~pymongo.database.Database.previous_error` + - :meth:`~pymongo.database.Database.reset_error_history` - :class:`~pymongo.master_slave_connection.MasterSlaveConnection` The JSON format for :class:`~bson.timestamp.Timestamp` has changed from diff --git a/pymongo/database.py b/pymongo/database.py index f5c505119..d606efd60 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -630,11 +630,26 @@ class Database(common.BaseObject): return list(self["system.profile"].find()) def error(self): - """Get a database error if one occured on the last operation. + """**DEPRECATED**: Get the error if one occurred on the last operation. + + This method is obsolete: all MongoDB write operations (insert, update, + remove, and so on) use the write concern ``w=1`` and report their + errors by default. + + This method must be called in the same + :doc:`request ` as the preceding operation, + otherwise it is unreliable. Requests are deprecated and will be removed + in PyMongo 3.0. Return None if the last operation was error-free. Otherwise return the error that occurred. + + .. versionchanged:: 2.8 + Deprecated. """ + warnings.warn("Database.error() is deprecated", + DeprecationWarning, stacklevel=2) + error = self.command("getlasterror", read_preference=ReadPreference.PRIMARY) error_msg = error.get("err", "") @@ -645,20 +660,51 @@ class Database(common.BaseObject): return error def last_status(self): - """Get status information from the last operation. + """**DEPRECATED**: Get status information from the last operation. + + This method is obsolete: all MongoDB write operations (insert, update, + remove, and so on) use the write concern ``w=1`` and report their + errors by default. + + This method must be called in the same + :doc:`request ` as the preceding operation, + otherwise it is unreliable. Requests are deprecated and will be removed + in PyMongo 3.0. Returns a SON object with status information. + + .. versionchanged:: 2.8 + Deprecated. """ + warnings.warn("last_status() is deprecated", + DeprecationWarning, stacklevel=2) + return self.command("getlasterror", read_preference=ReadPreference.PRIMARY) def previous_error(self): - """Get the most recent error to have occurred on this database. + """**DEPRECATED**: Get the most recent error on this database. + + This method is obsolete: all MongoDB write operations (insert, update, + remove, and so on) use the write concern ``w=1`` and report their + errors by default. + + This method must be called in the same + :doc:`request ` as the preceding operation, + otherwise it is unreliable. Requests are deprecated and will be removed + in PyMongo 3.0. Furthermore, the underlying database command + ``getpreverror`` will be removed in a future MongoDB release. Only returns errors that have occurred since the last call to - `Database.reset_error_history`. Returns None if no such errors have + :meth:`reset_error_history`. Returns None if no such errors have occurred. + + .. versionchanged:: 2.8 + Deprecated. """ + warnings.warn("previous_error() is deprecated", + DeprecationWarning, stacklevel=2) + error = self.command("getpreverror", read_preference=ReadPreference.PRIMARY) if error.get("err", 0) is None: @@ -666,11 +712,27 @@ class Database(common.BaseObject): return error def reset_error_history(self): - """Reset the error history of this database. + """**DEPRECATED**: Reset the error history of this database. - Calls to `Database.previous_error` will only return errors that have + This method is obsolete: all MongoDB write operations (insert, update, + remove, and so on) use the write concern ``w=1`` and report their + errors by default. + + This method must be called in the same + :doc:`request ` as the preceding operation, + otherwise it is unreliable. Requests are deprecated and will be removed + in PyMongo 3.0. Furthermore, the underlying database command + ``reseterror`` will be removed in a future MongoDB release. + + Calls to :meth:`previous_error` will only return errors that have occurred since the most recent call to this method. + + .. versionchanged:: 2.8 + Deprecated. """ + warnings.warn("reset_error_history() is deprecated", + DeprecationWarning, stacklevel=2) + self.command("reseterror", read_preference=ReadPreference.PRIMARY)