From 388339e187ddc8147b31cd351deb52d6fdb53405 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Thu, 21 Jun 2018 12:03:42 -0700 Subject: [PATCH] PYTHON-1591 - Deprecate Collection.parallel_scan --- doc/changelog.rst | 2 ++ pymongo/collection.py | 8 +++++++- test/test_collection.py | 4 ++++ test/test_session.py | 5 ++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 0bf387487..7268471d7 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -65,6 +65,8 @@ Deprecations: :meth:`~pymongo.mongo_client.MongoClient.list_database_names` instead. - Deprecated :meth:`~pymongo.database.Database.collection_names`. Use :meth:`~pymongo.database.Database.list_collection_names` instead. +- Deprecated :meth:`~pymongo.collection.Collection.parallel_scan`. MongoDB 4.2 + will remove the parallelCollectionScan command. Unavoidable breaking changes: diff --git a/pymongo/collection.py b/pymongo/collection.py index 1d68dda94..a2e84d768 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -1450,7 +1450,7 @@ class Collection(common.BaseObject): return RawBatchCursor(self, *args, **kwargs) def parallel_scan(self, num_cursors, session=None, **kwargs): - """Scan this entire collection in parallel. + """**DEPRECATED**: Scan this entire collection in parallel. Returns a list of up to ``num_cursors`` cursors that can be iterated concurrently. As long as the collection is not modified during @@ -1492,6 +1492,9 @@ class Collection(common.BaseObject): .. note:: Requires server version **>= 2.5.5**. + .. versionchanged:: 3.7 + Deprecated. + .. versionchanged:: 3.6 Added ``session`` parameter. @@ -1504,6 +1507,9 @@ class Collection(common.BaseObject): Removed support for arbitrary keyword arguments, since the parallelCollectionScan command has no optional arguments. """ + warnings.warn("parallel_scan is deprecated. MongoDB 4.2 will remove " + "the parallelCollectionScan command.", + DeprecationWarning, stacklevel=2) cmd = SON([('parallelCollectionScan', self.__name), ('numCursors', num_cursors)]) cmd.update(kwargs) diff --git a/test/test_collection.py b/test/test_collection.py index d948633fa..6b196cf7b 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -1662,6 +1662,8 @@ class TestCollection(IntegrationTest): self.assertTrue(cursor.alive) @client_context.require_no_mongos + @client_context.require_version_max(4, 1, 0) + @ignore_deprecations def test_parallel_scan(self): db = self.db db.drop_collection("test") @@ -1688,7 +1690,9 @@ class TestCollection(IntegrationTest): @client_context.require_no_mongos @client_context.require_version_min(3, 3, 10) + @client_context.require_version_max(4, 1, 0) @client_context.require_test_commands + @ignore_deprecations def test_parallel_scan_max_time_ms(self): self.client.admin.command("configureFailPoint", "maxTimeAlwaysTimeOut", diff --git a/test/test_session.py b/test/test_session.py index c7edc8c18..41b08f674 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -320,6 +320,8 @@ class TestSession(IntegrationTest): (coll.aggregate, [[]], {})) @client_context.require_no_mongos + @client_context.require_version_max(4, 1, 0) + @ignore_deprecations def test_parallel_collection_scan(self): listener = self.listener client = self.client @@ -771,7 +773,8 @@ class TestCausalConsistency(unittest.TestCase): self._test_reads( lambda coll, session: coll.inline_map_reduce( 'function() {}', 'function() {}', session=session)) - if not client_context.is_mongos: + if (not client_context.is_mongos and + not client_context.version.at_least(4, 1, 0)): def scan(coll, session): cursors = coll.parallel_scan(1, session=session) for cur in cursors: