diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-09-09 19:29:09 +0000 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-09-09 19:29:09 +0000 |
| commit | 3231d1062d0930a9344dd8550243331696ca27eb (patch) | |
| tree | e56b546a24d754a98f1238f781ea578df8e24d16 /python | |
| parent | fdc0c4f48e6839142db30c2fb9c6d5c84b9eba90 (diff) | |
| download | vyos-1x-3231d1062d0930a9344dd8550243331696ca27eb.tar.gz vyos-1x-3231d1062d0930a9344dd8550243331696ca27eb.zip | |
vyos.utils: T9269: no zero-component key path for an empty dict
dict_to_key_paths() yields the path leading to an empty dict, which is a
valueless leaf node. An empty dict at the top level means "no
configuration" and yielded a single zero-component path, making
dict_to_paths_values() report an option named ''.
A bare "interfaces ethernet eth1" - as found in a container, where no
hw-id is deployed - could therefore not be added to a bond:
Cannot add interface "eth1" to bond, it has a "" assigned!
interfaces_ethernet.py recorded the same phantom path in
bond_blocked_changes. configdiff.py was immune, owner([]) is falsy.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/dict.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/python/vyos/utils/dict.py b/python/vyos/utils/dict.py index 3fcda902f..058717265 100644 --- a/python/vyos/utils/dict.py +++ b/python/vyos/utils/dict.py @@ -315,7 +315,12 @@ def dict_to_key_paths(d: dict) -> list: """ def func(d, path): if isinstance(d, dict): - if not d: + # An empty dict is a valueless leaf node and yields the path that + # leads to it - but only if there is one. An empty dict at the top + # level means "no configuration at all", which must yield nothing + # instead of a single empty path: consumers join the components + # into a dotted option name, and '' is not an option + if not d and path: yield path for k, v in d.items(): for r in func(v, path + [k]): |
