PYTHON-1709 Always use codec_options in Database.current_op

This commit is contained in:
Shane Harvey 2019-03-12 18:47:00 -07:00
parent 59c3a22115
commit da2ba8d7ed
3 changed files with 17 additions and 3 deletions

View File

@ -60,6 +60,11 @@ Changes in Version 3.8.0.dev0
- :class:`~bson.objectid.ObjectId` now implements the `ObjectID specification
version 0.2 <https://github.com/mongodb/specifications/blob/master/source/objectid.rst>`_.
- :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
...............

View File

@ -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",

View File

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