Skip to content

Commit

Permalink
_build_kwargs fix, don't convert int-y things to floats
Browse files Browse the repository at this point in the history
  • Loading branch information
ross committed Mar 8, 2024
1 parent 3acfd17 commit 4b229fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions octodns/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,14 @@ def _build_kwargs(self, source):
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
Expand Down
13 changes: 13 additions & 0 deletions tests/test_octodns_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ def test_build_kwargs(self):

environ['OCTODNS_TEST_1'] = '42'
environ['OCTODNS_TEST_2'] = 'string'
environ['OCTODNS_TEST_3'] = '43.44'

# empty
self.assertEqual({}, manager._build_kwargs({}))
Expand Down Expand Up @@ -1202,6 +1203,18 @@ def test_build_kwargs(self):
),
)

# 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):
Expand Down

0 comments on commit 4b229fb

Please sign in to comment.