PYTHON-526 Remove get/set/unset_lasterror_options
Use <object>.write_concern instead.
This commit is contained in:
parent
37abda5e25
commit
de23b63994
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=<bool>, w=<int/string>, wtimeout=<int>,
|
||||
and fsync=<bool>.
|
||||
|
||||
: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.
|
||||
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user