From de23b63994ec8f99a6c40253d884bfa1b6121462 Mon Sep 17 00:00:00 2001 From: behackett Date: Sat, 5 Apr 2014 12:27:38 -0700 Subject: [PATCH] PYTHON-526 Remove get/set/unset_lasterror_options Use .write_concern instead. --- doc/api/pymongo/collection.rst | 3 -- doc/api/pymongo/database.rst | 3 -- pymongo/common.py | 59 ----------------------- test/test_common.py | 85 ---------------------------------- 4 files changed, 150 deletions(-) diff --git a/doc/api/pymongo/collection.rst b/doc/api/pymongo/collection.rst index 9a94a270b..0fc883a78 100644 --- a/doc/api/pymongo/collection.rst +++ b/doc/api/pymongo/collection.rst @@ -53,7 +53,4 @@ .. automethod:: map_reduce .. automethod:: inline_map_reduce .. automethod:: find_and_modify - .. automethod:: get_lasterror_options - .. automethod:: set_lasterror_options - .. automethod:: unset_lasterror_options diff --git a/doc/api/pymongo/database.rst b/doc/api/pymongo/database.rst index 7fd2f22a1..349c88457 100644 --- a/doc/api/pymongo/database.rst +++ b/doc/api/pymongo/database.rst @@ -28,9 +28,6 @@ .. autoattribute:: secondary_acceptable_latency_ms .. autoattribute:: write_concern .. autoattribute:: uuid_subtype - .. automethod:: get_lasterror_options - .. automethod:: set_lasterror_options - .. automethod:: unset_lasterror_options .. autoclass:: pymongo.database.SystemJS diff --git a/pymongo/common.py b/pymongo/common.py index e05d8715c..6329042ed 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -527,65 +527,6 @@ class BaseObject(object): uuid_subtype = property(__get_uuid_subtype, __set_uuid_subtype) - def get_lasterror_options(self): - """DEPRECATED: Use :attr:`write_concern` instead. - - Returns a dict of the getlasterror options set on this instance. - - .. versionchanged:: 2.4 - Deprecated get_lasterror_options. - .. versionadded:: 2.0 - """ - warnings.warn("get_lasterror_options is deprecated. Please use " - "write_concern instead.", DeprecationWarning, - stacklevel=2) - return self.__write_concern.copy() - - def set_lasterror_options(self, **kwargs): - """DEPRECATED: Use :attr:`write_concern` instead. - - Set getlasterror options for this instance. - - Valid options include j=, w=, wtimeout=, - and fsync=. - - :Parameters: - - `**kwargs`: Options should be passed as keyword - arguments (e.g. w=2, fsync=True) - - .. versionchanged:: 2.4 - Deprecated set_lasterror_options. - .. versionadded:: 2.0 - """ - warnings.warn("set_lasterror_options is deprecated. Please use " - "write_concern instead.", DeprecationWarning, - stacklevel=2) - for key, value in kwargs.iteritems(): - self.__set_write_concern_option(key, value) - - def unset_lasterror_options(self, *options): - """DEPRECATED: Use :attr:`write_concern` instead. - - Unset getlasterror options for this instance. - - If no options are passed unsets all getlasterror options. - - :Parameters: - - `*options`: The list of options to unset. - - .. versionchanged:: 2.4 - Deprecated unset_lasterror_options. - .. versionadded:: 2.0 - """ - warnings.warn("unset_lasterror_options is deprecated. Please use " - "write_concern instead.", DeprecationWarning, - stacklevel=2) - if len(options): - for option in options: - self.__write_concern.pop(option, None) - else: - self.__write_concern = WriteConcern() - def _get_wc_override(self): """Get write concern override. diff --git a/test/test_common.py b/test/test_common.py index ff23b31b2..fd927e618 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -41,91 +41,6 @@ except ImportError: class TestCommon(unittest.TestCase): - def test_baseobject(self): - - # MongoClient test - c = MongoClient(pair) - self.assertEqual({}, c.get_lasterror_options()) - db = c.pymongo_test - db.drop_collection("test") - self.assertEqual({}, db.get_lasterror_options()) - coll = db.test - self.assertEqual({}, coll.get_lasterror_options()) - - self.assertEqual((True, {}), coll._get_write_mode({})) - coll.write_concern.update(w=1) - self.assertEqual((True, {'w': 1}), coll._get_write_mode({})) - coll.write_concern.update(w=3) - self.assertEqual((True, {'w': 3}), coll._get_write_mode({})) - coll.write_concern.update(w=0) - self.assertEqual((False, {}), coll._get_write_mode({})) - - c = MongoClient(pair, w='majority', - wtimeout=300, fsync=True, j=True) - d = {'w': 'majority', 'wtimeout': 300, 'fsync': True, 'j': True} - self.assertEqual(d, c.get_lasterror_options()) - db = c.pymongo_test - self.assertEqual(d, db.get_lasterror_options()) - coll = db.test - self.assertEqual(d, coll.get_lasterror_options()) - - c = MongoClient('mongodb://%s/?' - 'w=2;wtimeoutMS=300;fsync=true;' - 'journal=true' % (pair,)) - d = {'w': 2, 'wtimeout': 300, 'fsync': True, 'j': True} - self.assertEqual(d, c.get_lasterror_options()) - - c = MongoClient('mongodb://%s/?' - 'w=1;wtimeout=300;' - 'fsync=true;j=true' % (pair,)) - d = {'w': 1, 'wtimeout': 300, 'fsync': True, 'j': True} - self.assertEqual(d, c.get_lasterror_options()) - self.assertEqual(d, c.write_concern) - db = c.pymongo_test - self.assertEqual(d, db.get_lasterror_options()) - self.assertEqual(d, db.write_concern) - coll = db.test - self.assertEqual(d, coll.get_lasterror_options()) - self.assertEqual(d, coll.write_concern) - cursor = coll.find() - - c.unset_lasterror_options() - self.assertEqual({}, c.get_lasterror_options()) - self.assertEqual({}, c.write_concern) - db = c.pymongo_test - self.assertEqual({}, db.get_lasterror_options()) - self.assertEqual({}, db.write_concern) - coll = db.test - self.assertEqual({}, coll.get_lasterror_options()) - self.assertEqual({}, coll.write_concern) - - coll.set_lasterror_options(fsync=True) - self.assertEqual({'fsync': True}, coll.get_lasterror_options()) - self.assertEqual({'fsync': True}, coll.write_concern) - self.assertEqual({}, db.get_lasterror_options()) - self.assertEqual({}, db.write_concern) - self.assertEqual({}, c.get_lasterror_options()) - self.assertEqual({}, c.write_concern) - - db.set_lasterror_options(w='majority') - self.assertEqual({'fsync': True}, coll.get_lasterror_options()) - self.assertEqual({'fsync': True}, coll.write_concern) - self.assertEqual({'w': 'majority'}, db.get_lasterror_options()) - self.assertEqual({'w': 'majority'}, db.write_concern) - self.assertEqual({}, c.get_lasterror_options()) - self.assertEqual({}, c.write_concern) - - self.assertRaises(ConfigurationError, coll.set_lasterror_options, foo=20) - - coll.remove() - coll.unset_lasterror_options() - coll.set_lasterror_options(w=4, wtimeout=10) - # Fails if we don't have 4 active nodes or we don't have replication... - self.assertRaises(OperationFailure, coll.insert, {'foo': 'bar'}) - # Succeeds since we override the lasterror settings per query. - self.assertTrue(coll.insert({'foo': 'bar'}, fsync=True)) - drop_collections(db) - def test_uuid_subtype(self): if not have_uuid: raise SkipTest("No uuid module")