Module: check_mk
Branch: master
Commit: dc2cfc45e3d080a8995bae1baa866cef02f25938
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc2cfc45e3d080…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 23 10:41:34 2018 +0100
Fixed dictionary element evaluation during initialization
The Dictionary() valuespec elements can either be a list of elements
or a function reference which is meant to generate the elements on
demand in the moment they are needed instead of the construction time
of the valuespec.
There are attributes optional_keys and required_keys which tell the
Dictionary() valuespec how to handle the single elements.
There are multiple ways to tell the object that none of the elements
is optional. It can be done by either setting it to None, False or
an empty list.
And here comes the bug: When the "optional_keys" attribute was set to an
empty list, the element generation function was called while it wasn't
needed to call it.
In many situations this is not a real problem because mostly the element
function is cheap. But we had a situation where the element function
initialized livestatus connections to all sites during the program
initialization phase where such things should not be done.
Change-Id: I33b4a80aa9ebcf587702f8e1633cbc833c127503
---
cmk/gui/valuespec.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmk/gui/valuespec.py b/cmk/gui/valuespec.py
index 977116e..e2ab59c 100644
--- a/cmk/gui/valuespec.py
+++ b/cmk/gui/valuespec.py
@@ -3482,7 +3482,7 @@ class Dictionary(ValueSpec):
self._default_keys = kwargs.get("default_keys", []) # keys present in
default value
if "optional_keys" in kwargs:
ok = kwargs["optional_keys"]
- if isinstance(ok, list):
+ if isinstance(ok, list) and ok:
self._required_keys = \
[ e[0] for e in self._get_elements() if e[0] not in ok ]
self._optional_keys = True