mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix matching of integer keys in nested subdicts
This commit is contained in:
parent
5a73ef699f
commit
22d3087e6b
2 changed files with 23 additions and 1 deletions
|
@ -827,7 +827,21 @@ def traverse_dict_and_list(data, key, default=None, delimiter=DEFAULT_TARGET_DEL
|
|||
else:
|
||||
try:
|
||||
ptr = ptr[each]
|
||||
except (KeyError, TypeError):
|
||||
except KeyError:
|
||||
# Late import to avoid circular import
|
||||
import salt.utils.args
|
||||
|
||||
# YAML-load the current key (catches integer dict keys)
|
||||
try:
|
||||
loaded_key = salt.utils.args.yamlify_arg(each)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return default
|
||||
if loaded_key != each:
|
||||
try:
|
||||
ptr = ptr[loaded_key]
|
||||
except (KeyError, TypeError):
|
||||
return default
|
||||
except TypeError:
|
||||
return default
|
||||
return ptr
|
||||
|
||||
|
|
|
@ -226,6 +226,14 @@ class DataTestCase(TestCase):
|
|||
{"not_found": "not_found"},
|
||||
),
|
||||
)
|
||||
# Traverse and match integer key in a nested dict
|
||||
# https://github.com/saltstack/salt/issues/56444
|
||||
self.assertEqual(
|
||||
"it worked",
|
||||
salt.utils.data.traverse_dict_and_list(
|
||||
{"foo": {1234: "it worked"}}, "foo:1234", "it didn't work",
|
||||
),
|
||||
)
|
||||
|
||||
def test_compare_dicts(self):
|
||||
ret = salt.utils.data.compare_dicts(old={"foo": "bar"}, new={"foo": "bar"})
|
||||
|
|
Loading…
Add table
Reference in a new issue