From 4b229fbf820e8fcca06c73c7b45dd77f62b1fba1 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 8 Mar 2024 07:51:09 -0800 Subject: [PATCH 1/2] _build_kwargs fix, don't convert int-y things to floats --- octodns/manager.py | 10 +++++++--- tests/test_octodns_manager.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/octodns/manager.py b/octodns/manager.py index 7b26f83..e34d3a0 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -388,10 +388,14 @@ class Manager(object): f'Incorrect provider config, missing env var {env_var}, {source.context}' ) try: - # try converting the value to a number to see if it - # converts - v = float(v) + if '.' in v: + # has a dot, try converting it to a float + v = float(v) + else: + # no dot, try converting it to an int + v = int(v) except ValueError: + # just leave it as a string pass kwargs[k] = v diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index 5283769..b0d4019 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -1133,6 +1133,7 @@ class TestManager(TestCase): environ['OCTODNS_TEST_1'] = '42' environ['OCTODNS_TEST_2'] = 'string' + environ['OCTODNS_TEST_3'] = '43.44' # empty self.assertEqual({}, manager._build_kwargs({})) @@ -1202,6 +1203,18 @@ class TestManager(TestCase): ), ) + # types/conversion + self.assertEqual( + {'int': 42, 'string': 'string', 'float': 43.44}, + manager._build_kwargs( + { + 'int': 'env/OCTODNS_TEST_1', + 'string': 'env/OCTODNS_TEST_2', + 'float': 'env/OCTODNS_TEST_3', + } + ), + ) + class TestMainThreadExecutor(TestCase): def test_success(self): From 7f27316548bf73977b93424780a9b5b17f6c2543 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 8 Mar 2024 08:06:43 -0800 Subject: [PATCH 2/2] Version 1.5.1 bump & changelog update --- CHANGELOG.md | 6 ++++++ octodns/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8bc762..1d53765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v1.5.1 - 2024-03-08 - env/* type conversion fix + +* Improved env variable to parameter type conversion logic, avoid converting + all numbers to float which caused some formatting issues in things that + weren't being careful enough. + ## v1.5.0 - 2024-02-26 - Checksums, nested expansion, & flexable values * Beta support for Manager.enable_checksum and octodns-sync --checksum Allows a diff --git a/octodns/__init__.py b/octodns/__init__.py index 12c987c..ebfb66e 100644 --- a/octodns/__init__.py +++ b/octodns/__init__.py @@ -1,4 +1,4 @@ 'OctoDNS: DNS as code - Tools for managing DNS across multiple providers' # TODO: remove __VERSION__ w/2.x -__version__ = __VERSION__ = '1.5.0' +__version__ = __VERSION__ = '1.5.1'