diff --git a/ddtrace/contrib/internal/pymongo/client.py b/ddtrace/contrib/internal/pymongo/client.py index f8441f3091b..d9a59bac945 100644 --- a/ddtrace/contrib/internal/pymongo/client.py +++ b/ddtrace/contrib/internal/pymongo/client.py @@ -101,7 +101,10 @@ def _trace_topology_select_server(func, args, kwargs): # Ensure the pin used on the traced mongo client is passed down to the topology instance # This allows us to pass the same pin in traced server objects. topology_instance = get_argument_value(args, kwargs, 0, "self") - ddtrace.Pin.get_from(topology_instance).onto(server) + pin = ddtrace.Pin.get_from(topology_instance) + + if pin is not None: + pin.onto(server) return server diff --git a/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml new file mode 100644 index 00000000000..1f1ad12a669 --- /dev/null +++ b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + pymongo: add type checking to solve an issue where ``NoneType`` instead of expected ``Pin`` object would throw an error in ``TracedTopology`` method.