From da2ba8d7ed2b7b7a333dd5ee12f48bf482b3cb09 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Tue, 12 Mar 2019 18:47:00 -0700 Subject: [PATCH] PYTHON-1709 Always use codec_options in Database.current_op --- doc/changelog.rst | 5 +++++ pymongo/database.py | 6 +++--- test/test_database.py | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 3543a3b5c..6d0c64971 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -60,6 +60,11 @@ Changes in Version 3.8.0.dev0 - :class:`~bson.objectid.ObjectId` now implements the `ObjectID specification version 0.2 `_. +- :meth:`~pymongo.database.Database.current_op` now always uses the + ``Database``'s :attr:`~pymongo.database.Database.codec_options` + when decoding the command response. Previously the codec_options + was only used when the MongoDB server version was <= 3.0. + Issues Resolved ............... diff --git a/pymongo/database.py b/pymongo/database.py index 178679b8a..223941a15 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -828,9 +828,9 @@ class Database(common.BaseObject): cmd = SON([("currentOp", 1), ("$all", include_all)]) with self.__client._socket_for_writes(session) as sock_info: if sock_info.max_wire_version >= 4: - with self.__client._tmp_session(session) as s: - return sock_info.command("admin", cmd, session=s, - client=self.__client) + return self.__client.admin._command( + sock_info, cmd, codec_options=self.codec_options, + session=session) else: spec = {"$all": True} if include_all else {} return _first_batch(sock_info, "admin", "$cmd.sys.inprog", diff --git a/test/test_database.py b/test/test_database.py index c39ff0ae7..52f480a19 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -942,6 +942,15 @@ class TestDatabase(IntegrationTest): "maxTimeAlwaysTimeOut", mode="off") + def test_current_op_codec_options(self): + class MySON(SON): + pass + opts = CodecOptions(document_class=MySON) + db = self.client.get_database("pymongo_test", codec_options=opts) + current_op = db.current_op(True) + self.assertTrue(current_op['inprog']) + self.assertIsInstance(current_op, MySON) + if __name__ == "__main__": unittest.main()