Module: check_mk
Branch: master
Commit: 83b8c282655b612b48f3370be0fa0c6c3994dfcc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=83b8c282655b61…
Author: Andreas <ab(a)mathias-kettner.de>
Date: Thu Jun 14 17:39:20 2018 +0200
5821 FIX Fixed exception during configuration changes
This exception could happens on various instances. For example
when saving global settings or during the activate changes phase.
The exception text showed <tt>super(type, obj): obj must be an instance or subtype
of type</tt>.
Change-Id: Iac78617d4be8f802915cda1ebf08d09694f50878
---
.werks/5821 | 14 ++++++++++++++
web/htdocs/backup.py | 2 ++
web/htdocs/gui_background_job.py | 9 ++++++++-
web/htdocs/watolib.py | 11 +++++++----
web/plugins/webapi/webapi.py | 6 +++++-
5 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/.werks/5821 b/.werks/5821
new file mode 100644
index 0000000..bb96df8
--- /dev/null
+++ b/.werks/5821
@@ -0,0 +1,14 @@
+Title: Fixed exception during configuration changes
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1528990598
+
+This exception could happens on various instances. For example
+when saving global settings or during the activate changes phase.
+
+The exception text showed <tt>super(type, obj): obj must be an instance or subtype
of type</tt>.
diff --git a/web/htdocs/backup.py b/web/htdocs/backup.py
index f5bc8a2..f8adad4 100644
--- a/web/htdocs/backup.py
+++ b/web/htdocs/backup.py
@@ -1297,6 +1297,7 @@ class BackupTargetType(object):
@classmethod
def choices(cls):
choices = []
+ # TODO: subclasses with the same name may be registered multiple times, due to
execfile
for type_class in cls.__subclasses__(): # pylint: disable=no-member
choices.append((type_class.ident, type_class.title(),
type_class.valuespec()))
return sorted(choices, key=lambda x: x[1])
@@ -1304,6 +1305,7 @@ class BackupTargetType(object):
@classmethod
def get_type(cls, type_ident):
+ # TODO: subclasses with the same name may be registered multiple times, due to
execfile
for type_class in cls.__subclasses__(): # pylint: disable=no-member
if type_class.ident == type_ident:
return type_class
diff --git a/web/htdocs/gui_background_job.py b/web/htdocs/gui_background_job.py
index 077846c..63c7cdf 100644
--- a/web/htdocs/gui_background_job.py
+++ b/web/htdocs/gui_background_job.py
@@ -185,8 +185,15 @@ class GUIBackgroundJob(GUIBackgroundJobSnapshottedFunctions,
background_job.Back
@classmethod
def get_concrete_subclasses(cls):
- all_subclasses = []
+ # Note: Due to the strange execfile plugin mechanism, there is a risk
+ # that a class gets declared multiple times. We always use the last
+ # declaration of the given class
+ classes = {}
for subclass in cls.__subclasses__(): # pylint: disable=no-member
+ classes[subclass.__name__] = subclass
+
+ all_subclasses = []
+ for subclass in classes.values():
# Concrete subclasses have an attribute job_prefix
if hasattr(subclass, "job_prefix"):
all_subclasses.append(subclass)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index b9181cd..655cdc9 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -282,13 +282,16 @@ class ConfigDomain(object):
@classmethod
def all_classes(cls):
- subclasses = cls.__subclasses__() # pylint: disable=no-member
-
# Classes may be registered twice, only store one of the occurances.
# TODO(lm): Find the reason for this and solve this issue in the plugin
mechanism.
+ # NOTE: One reason is the rampant execfile usage in the plugin folders
+ # each language change creates additional class definitions
+
+ # The latest "fix" changes the behaviour to return the last declared
class with the
+ # same class name. This is usually a better idea, than returning outdated
classes
classes = {}
- for subclass in subclasses:
- classes.setdefault(subclass.__name__, subclass)
+ for subclass in cls.__subclasses__(): # pylint: disable=no-member
+ classes[subclass.__name__] = subclass
return classes.values()
diff --git a/web/plugins/webapi/webapi.py b/web/plugins/webapi/webapi.py
index ee553fe..0b4b4a5 100644
--- a/web/plugins/webapi/webapi.py
+++ b/web/plugins/webapi/webapi.py
@@ -134,7 +134,11 @@ def add_configuration_hash(response, configuration_object):
class APICallCollection(object):
@classmethod
def all_classes(cls):
- return cls.__subclasses__() # pylint: disable=no-member
+ classes = {}
+ for subclass in cls.__subclasses__(): # pylint: disable=no-member
+ classes[subclass.__name__] = subclass
+
+ return classes.values()
def get_api_calls(self):