Skip to content

Commit 885f4f9

Browse files
author
Emanuele Palazzetti
committed
[core] check properly the object id when deciding to clone or not the Pin
1 parent 65fa4ba commit 885f4f9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ddtrace/pin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_from(obj):
7171
pin_name = _DD_PIN_PROXY_NAME if isinstance(obj, wrapt.ObjectProxy) else _DD_PIN_NAME
7272
pin = getattr(obj, pin_name, None)
7373
# detect if the PIN has been inherited from a class
74-
if pin is not None and pin._target is not obj:
74+
if pin is not None and pin._target != id(obj):
7575
pin = pin.clone()
7676
pin.onto(obj)
7777
return pin

tests/test_instance_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def test_configuration_get_from(self):
2424
cfg = config.get_from(self.Klass)
2525
ok_(isinstance(cfg, dict))
2626

27+
def test_configuration_get_from_twice(self):
28+
# ensure the configuration is the same if `get_from` is used
29+
# in the same instance
30+
instance = self.Klass()
31+
cfg1 = config.get_from(instance)
32+
cfg2 = config.get_from(instance)
33+
ok_(cfg1 is cfg2)
34+
2735
def test_configuration_set(self):
2836
# ensure the configuration can be updated in the Pin
2937
instance = self.Klass()

0 commit comments

Comments
 (0)