Skip to content

Commit 545bd63

Browse files
fix(pymongo): use generic arguments for write_command (#3371) (#3372)
Pymongo 4.0.2 released which introduced a breaking change to the method signature of Socket.write_command: mongodb/mongo-python-driver@4.0.1...4.0.2diff-43b0ab0dab45c7b3e339879a4452c7dcb43a659ef6603532348a745e6405afd4R819 The patching attempted to match the signature exactly so the fix is trivial in just accepting args/kwargs and extracting what is needed from them. (cherry picked from commit da60df9) Co-authored-by: Kyle Verhoog <[email protected]>
1 parent 1a6bad3 commit 545bd63

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ddtrace/contrib/pymongo/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ...ext import net as netx
1818
from ...internal.compat import iteritems
1919
from ...internal.logger import get_logger
20+
from ...internal.utils import get_argument_value
2021
from .parse import parse_msg
2122
from .parse import parse_query
2223
from .parse import parse_spec
@@ -190,7 +191,8 @@ def command(self, dbname, spec, *args, **kwargs):
190191
with self.__trace(cmd):
191192
return self.__wrapped__.command(dbname, spec, *args, **kwargs)
192193

193-
def write_command(self, request_id, msg):
194+
def write_command(self, *args, **kwargs):
195+
msg = get_argument_value(args, kwargs, 1, "msg")
194196
cmd = None
195197
try:
196198
cmd = parse_msg(msg)
@@ -200,10 +202,10 @@ def write_command(self, request_id, msg):
200202
pin = ddtrace.Pin.get_from(self)
201203
# if we couldn't parse it, don't try to trace it.
202204
if not cmd or not pin or not pin.enabled():
203-
return self.__wrapped__.write_command(request_id, msg)
205+
return self.__wrapped__.write_command(*args, **kwargs)
204206

205207
with self.__trace(cmd) as s:
206-
result = self.__wrapped__.write_command(request_id, msg)
208+
result = self.__wrapped__.write_command(*args, **kwargs)
207209
if result:
208210
s.set_metric(mongox.ROWS, result.get("n", -1))
209211
return result
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
pymongo: fix ``write_command`` being patched with the wrong method signature.

0 commit comments

Comments
 (0)