Undeprecate message.insert().

In PyMongo 2.6, message.insert was replaced with _do_batched insert. It was
deprecated but not removed in case third-party libraries might rely on it. In
PyMongo 2.7 we implemented the Bulk API (PYTHON-630) and message.insert found a
new use.
This commit is contained in:
A. Jesse Jiryu Davis 2014-11-17 13:30:51 -05:00
parent 0e222c4c4c
commit 28cf3102a6
3 changed files with 5 additions and 53 deletions

View File

@ -158,10 +158,8 @@ static int init_insert_buffer(buffer_t buffer, int request_id, int options,
}
static PyObject* _cbson_insert_message(PyObject* self, PyObject* args) {
/* Note: As of PyMongo 2.6, this function is no longer used. It
* is being kept (with tests) for backwards compatibility with 3rd
* party libraries that may currently be using it, but will likely
* be removed in a future release. */
/* Used by the Bulk API to insert into pre-2.6 servers. Collection.insert
* uses _cbson_do_batched_insert. */
struct module_state *state = GETSTATE(self);
/* NOTE just using a random number as the request_id */
@ -279,14 +277,6 @@ static PyObject* _cbson_insert_message(PyObject* self, PyObject* args) {
return result;
}
PyDoc_STRVAR(_cbson_insert_message_doc,
"Create an insert message to be sent to MongoDB\n\
\n\
Note: As of PyMongo 2.6, this function is no longer used. It\n\
is being kept (with tests) for backwards compatibility with 3rd\n\
party libraries that may currently be using it, but will likely\n\
be removed in a future release.");
static PyObject* _cbson_update_message(PyObject* self, PyObject* args) {
/* NOTE just using a random number as the request_id */
struct module_state *state = GETSTATE(self);
@ -1196,7 +1186,7 @@ cmdfail:
static PyMethodDef _CMessageMethods[] = {
{"_insert_message", _cbson_insert_message, METH_VARARGS,
_cbson_insert_message_doc},
"Create an insert message to be sent to MongoDB"},
{"_update_message", _cbson_update_message, METH_VARARGS,
"create an update message to be sent to MongoDB"},
{"_query_message", _cbson_query_message, METH_VARARGS,

View File

@ -82,11 +82,8 @@ def insert(collection_name, docs, check_keys,
safe, last_error_args, continue_on_error, uuid_subtype):
"""Get an **insert** message.
.. note:: As of PyMongo 2.6, this function is no longer used. It
is being kept (with tests) for backwards compatibility with 3rd
party libraries that may currently be using it, but will likely
be removed in a future release.
Used by the Bulk API to insert into pre-2.6 servers. Collection.insert
uses _do_batched_insert.
"""
options = 0
if continue_on_error:

View File

@ -1876,41 +1876,6 @@ class TestCollection(IntegrationTest):
self.assertEqual(n_docs, self.db.test.count())
self.db.test.remove()
# Starting in PyMongo 2.6 we no longer use message.insert for inserts, but
# message.insert is part of the public API. Do minimal testing here; there
# isn't really a better place.
def test_insert_message_creation(self):
send = self.db.connection._send_message
name = "%s.%s" % (self.db.name, "test")
def do_insert(args):
send(message_module.insert(*args), args[3])
self.db.drop_collection("test")
self.db.test.insert({'_id': 0}, w=1)
self.assertTrue(1, self.db.test.count())
simple_args = (name, [{'_id': 0}], True, False, {}, False, 3)
gle_args = (name, [{'_id': 0}], True, True, {'w': 1}, False, 3)
coe_args = (name, [{'_id': 0}, {'_id': 1}],
True, True, {'w': 1}, True, 3)
self.assertEqual(None, do_insert(simple_args))
self.assertTrue(1, self.db.test.count())
self.assertRaises(DuplicateKeyError, do_insert, gle_args)
self.assertTrue(1, self.db.test.count())
self.assertRaises(DuplicateKeyError, do_insert, coe_args)
self.assertTrue(2, self.db.test.count())
doc = {'_id': 2, 'uuid': uuid.uuid4()}
uuid_sub_args = (name, [doc],
True, True, {'w': 1}, True, 6)
do_insert(uuid_sub_args)
coll = self.db.test
self.assertNotEqual(doc, coll.find_one({'_id': 2}))
coll.uuid_subtype = 6
self.assertEqual(doc, coll.find_one({'_id': 2}))
@client_context.require_version_min(1, 1, 1)
def test_map_reduce(self):
db = self.db