Skip to content

Commit 513cd2c

Browse files
authored
Merge pull request #817 from DataDog/0.20.4-dev
Release 0.20.4
2 parents c8b1f40 + 0fa798d commit 513cd2c

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

ddtrace/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .tracer import Tracer
55
from .settings import config
66

7-
__version__ = '0.20.3'
7+
__version__ = '0.20.4'
88

99
# a global tracer instance with integration settings
1010
tracer = Tracer()

ddtrace/utils/attrdict.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ def __getattr__(self, key):
2222
return object.__getattribute__(self, key)
2323

2424
def __setattr__(self, key, value):
25-
# Allow overwriting an existing attribute, e.g. `self.global_config = dict()`
26-
if hasattr(self, key):
25+
# 1) Ensure if the key exists from a dict key we always prefer that
26+
# 2) If we do not have an existing key but we do have an attr, set that
27+
# 3) No existing key or attr exists, so set a key
28+
if key in self:
29+
# Update any existing key
30+
self[key] = value
31+
elif hasattr(self, key):
32+
# Allow overwriting an existing attribute, e.g. `self.global_config = dict()`
2733
object.__setattr__(self, key, value)
2834
else:
35+
# Set a new key
2936
self[key] = value

tests/test_instance_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from ddtrace import config
66
from ddtrace.pin import Pin
7+
from ddtrace.settings import IntegrationConfig
78

89

910
class InstanceConfigTestCase(TestCase):
@@ -100,3 +101,32 @@ def test_configuration_copy_upside_down(self):
100101
cfg = config.get_from(instance)
101102
# it should have users updated value
102103
eq_(cfg['service_name'], 'metrics')
104+
105+
def test_config_attr_and_key(self):
106+
"""
107+
This is a regression test for when mixing attr attribute and key
108+
access we would set the value of the attribute but not the key
109+
"""
110+
integration_config = IntegrationConfig(config)
111+
112+
# Our key and attribute do not exist
113+
self.assertFalse(hasattr(integration_config, 'distributed_tracing'))
114+
self.assertNotIn('distributed_tracing', integration_config)
115+
116+
# Initially set and access
117+
integration_config['distributed_tracing'] = True
118+
self.assertTrue(integration_config['distributed_tracing'])
119+
self.assertTrue(integration_config.get('distributed_tracing'))
120+
self.assertTrue(integration_config.distributed_tracing)
121+
122+
# Override by key and access
123+
integration_config['distributed_tracing'] = False
124+
self.assertFalse(integration_config['distributed_tracing'])
125+
self.assertFalse(integration_config.get('distributed_tracing'))
126+
self.assertFalse(integration_config.distributed_tracing)
127+
128+
# Override by attr and access
129+
integration_config.distributed_tracing = None
130+
self.assertIsNone(integration_config['distributed_tracing'])
131+
self.assertIsNone(integration_config.get('distributed_tracing'))
132+
self.assertIsNone(integration_config.distributed_tracing)

0 commit comments

Comments
 (0)