From 8598a765e8ac9904cacc4abe858873d8a801ef95 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 19 Oct 2020 12:10:43 +0200 Subject: unittests: T2995: vyos_dict_search() must return None on non-existing keys The current wversion unfortunately will raise a KeyError: >>> data = {} >>> vyos_dict_search('foo', data) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/vyos/util.py", line 685, in vyos_dict_search return dict[path] KeyError: 'foo' --- python/vyos/util.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python') diff --git a/python/vyos/util.py b/python/vyos/util.py index 79e11a86d..b5f0ea36e 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -682,6 +682,8 @@ def vyos_dict_search(path, dict): parts = path.split('.') inside = parts[:-1] if not inside: + if path not in dict: + return None return dict[path] c = dict for p in parts[:-1]: -- cgit v1.2.3