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()