Skip to content

Commit

Permalink
fix(pymongo): add pin type check (#11145)
Browse files Browse the repository at this point in the history
Small type check fix for expected `Pin` type to unblock #11041

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
quinna-h authored Oct 30, 2024
1 parent 6b5dece commit f3b5275
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ddtrace/contrib/internal/pymongo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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


Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f3b5275

Please sign in to comment.