Skip to content

Commit da2ba8d

Browse files
committed
PYTHON-1709 Always use codec_options in Database.current_op
1 parent 59c3a22 commit da2ba8d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

doc/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Changes in Version 3.8.0.dev0
6060
- :class:`~bson.objectid.ObjectId` now implements the `ObjectID specification
6161
version 0.2 <https://github.com/mongodb/specifications/blob/master/source/objectid.rst>`_.
6262

63+
- :meth:`~pymongo.database.Database.current_op` now always uses the
64+
``Database``'s :attr:`~pymongo.database.Database.codec_options`
65+
when decoding the command response. Previously the codec_options
66+
was only used when the MongoDB server version was <= 3.0.
67+
6368
Issues Resolved
6469
...............
6570

pymongo/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@ def current_op(self, include_all=False, session=None):
828828
cmd = SON([("currentOp", 1), ("$all", include_all)])
829829
with self.__client._socket_for_writes(session) as sock_info:
830830
if sock_info.max_wire_version >= 4:
831-
with self.__client._tmp_session(session) as s:
832-
return sock_info.command("admin", cmd, session=s,
833-
client=self.__client)
831+
return self.__client.admin._command(
832+
sock_info, cmd, codec_options=self.codec_options,
833+
session=session)
834834
else:
835835
spec = {"$all": True} if include_all else {}
836836
return _first_batch(sock_info, "admin", "$cmd.sys.inprog",

test/test_database.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,15 @@ def test_command_max_time_ms(self):
942942
"maxTimeAlwaysTimeOut",
943943
mode="off")
944944

945+
def test_current_op_codec_options(self):
946+
class MySON(SON):
947+
pass
948+
opts = CodecOptions(document_class=MySON)
949+
db = self.client.get_database("pymongo_test", codec_options=opts)
950+
current_op = db.current_op(True)
951+
self.assertTrue(current_op['inprog'])
952+
self.assertIsInstance(current_op, MySON)
953+
945954

946955
if __name__ == "__main__":
947956
unittest.main()

0 commit comments

Comments
 (0)