From 81d50cd33ed38463a7207cc782d9158c414bedce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 4 Jun 2021 21:49:02 +0200 Subject: [PATCH] backwards compatibility, 2.17.1 --- CHANGELOG.md | 3 +++ satella/__init__.py | 2 +- satella/opentracing/trace.py | 9 ++++++++- tests/test_opentracing.py | 6 ++++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92422957..990850b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,4 @@ # v2.17.1 + +* add backwards compatibility for tags_factory + diff --git a/satella/__init__.py b/satella/__init__.py index d41597e9..d49a0d72 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.17.1a1' +__version__ = '2.17.1' diff --git a/satella/opentracing/trace.py b/satella/opentracing/trace.py index 73923a6b..6596c07a 100644 --- a/satella/opentracing/trace.py +++ b/satella/opentracing/trace.py @@ -52,7 +52,14 @@ def trace_function(tracer, name: str, tags: tp.Optional[dict] = None, tags = {} my_tags = copy.copy(tags) for key, value in tags_factory: - my_tags[key] = value(*args, **kwargs) + try: + v = value(*args, **kwargs) + except TypeError: + warnings.warn('You are using the deprecated single-parameter version ' + 'of tags_factory. Please upgrade to the newer one.', + DeprecationWarning) + v = value(args) + my_tags[key] = v with tracer.start_active_span(name, tags=my_tags): return fun(*args, **kwargs) diff --git a/tests/test_opentracing.py b/tests/test_opentracing.py index d79e38cb..acbcbc19 100644 --- a/tests/test_opentracing.py +++ b/tests/test_opentracing.py @@ -14,7 +14,7 @@ class TestOpentracing(unittest.TestCase): self.start_active_span_called = True def start_active_span(self, *args, tags=None, **kwargs): - slf.assertEqual(tags, {'a': 'b', 'c': 'd'}) + slf.assertEqual(tags, {'a': 'b', 'c': 'd', 'e': 'f'}) class MockScope(mock.Mock): def __enter__(self): @@ -28,7 +28,9 @@ class TestOpentracing(unittest.TestCase): tracer = MockTracer() @trace_function(tracer, 'trace_me', - tags_factory= {('a', lambda: 'b'), ('c', lambda: 'd')}) + tags_factory= {'a': lambda: 'b', + 'c': lambda: 'd', + 'e': (lambda args: 'f')}) def trace_me(): pass -- GitLab