Skip to content

Commit 834b5ac

Browse files
fix: null values for defaults in spec (#379)
## 📝 Description **What does this PR do and why is this change necessary?** If the default value isn't set in the config or provided as a argument it will cause a error. Now it checks if neither are provided and ignores it. ## ✔️ How to Test **What are the steps to reproduce the issue or verify the changes?** remove a default value from your config and attempt to create a instance resolves [#378]
1 parent f2d8dd5 commit 834b5ac

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

linodecli/configuration/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def plugin_get_value(self, key):
206206
# TODO: this is more of an argparsing function than it is a config function
207207
# might be better to move this to argparsing during refactor and just have
208208
# configuration return defaults or keys or something
209-
def update(self, namespace, allowed_defaults):
209+
def update(self, namespace, allowed_defaults): #pylint: disable=too-many-branches
210210
"""
211211
This updates a Namespace (as returned by ArgumentParser) with config values
212212
if they aren't present in the Namespace already.
@@ -236,7 +236,9 @@ def update(self, namespace, allowed_defaults):
236236
if self.config.has_option(username, key):
237237
value = self.config.get(username, key)
238238
else:
239-
value = allowed_defaults[key]
239+
value = ns_dict[key]
240+
if not value:
241+
continue
240242
if key == "authorized_users":
241243
ns_dict[key] = [value]
242244
warn_dict[key] = [value]

tests/configuration.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ def test_update(self):
178178
parser.add_argument('--plugin-testplugin-testkey')
179179
ns = parser.parse_args(['--testkey', 'testvalue'])
180180

181-
update_dict = {
182-
'newkey': 'newvalue',
183-
'authorized_users': ['user1'],
184-
'plugin-testplugin-testkey': 'plugin-value',
185-
}
181+
conf.username = 'tester'
182+
conf.config.add_section('tester')
183+
conf.config.set('tester', 'token', 'testtoken')
184+
conf.config.set('tester', 'newkey', 'newvalue')
185+
conf.config.set('tester', 'authorized_users', 'tester')
186+
conf.config.set('tester', 'plugin-testplugin-testkey', 'plugin-value')
187+
allowed_defaults = {'newkey', 'authorized_users', 'plugin-testplugin-testkey'}
186188

187189
f = io.StringIO()
188190
with contextlib.redirect_stdout(f):
189-
result = vars(conf.update(ns, update_dict))
191+
result = vars(conf.update(ns, allowed_defaults))
190192

191193
self.assertTrue("--no-defaults" in f.getvalue())
192194
self.assertEqual(result.get("newkey"), "newvalue")

0 commit comments

Comments
 (0)