diff --git a/novaclient/tests/unit/test_utils.py b/novaclient/tests/unit/test_utils.py index 64a947ea5..919d4cb2b 100644 --- a/novaclient/tests/unit/test_utils.py +++ b/novaclient/tests/unit/test_utils.py @@ -340,7 +340,8 @@ class FlattenTestCase(test_utils.TestCase): 'b4': {'c1': ['l', 'l', ['l']], 'c2': 'string'}}, 'a2': ['l'], - 'a3': ('t',)}) + 'a3': ('t',), + 'a4': {}}) self.assertEqual({'a1_b1': 1234, 'a1_b2': 'string', @@ -348,7 +349,8 @@ class FlattenTestCase(test_utils.TestCase): 'a1_b4_c1': ['l', 'l', ['l']], 'a1_b4_c2': 'string', 'a2': ['l'], - 'a3': ('t',)}, + 'a3': ('t',), + 'a4': {}}, squashed) def test_pretty_choice_dict(self): diff --git a/novaclient/utils.py b/novaclient/utils.py index d7573758a..093bc9619 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -210,7 +210,7 @@ def _flatten(data, prefix=None): if isinstance(data, dict): for key, value in six.iteritems(data): new_key = '%s_%s' % (prefix, key) if prefix else key - if isinstance(value, (dict, list)): + if isinstance(value, (dict, list)) and value: for item in _flatten(value, new_key): yield item else: