Closed gmarjanidze closed 4 years ago
I can confirm this occurs on master
branch.
I'm not as familiar with the backend code so I don't have a solution to this. I do know that hipchat is based on xmpp backend and the plugin search logic matches both because of the inheritance.
I suspect the fix is somewhere in the backend_plugin_manager.py
file. It's likely in the logic searching for matches.
As in hipchat.py (HipChat backend module) the XMPPBackend class (from which the HipchatBackend class is derived) is imported like so:
from errbot.backends.xmpp import XMPPRoomOccupant, XMPPBackend, XMPPConnection, split_identifier
inspect.getmembers in PluginInfo.load_plugin_classes method (defined in plugin_info.py file) returns XMPPBackend and HipchatBackend (in case when base_module_name='hipchat').
So what if we modify the following function in BackendPluginManager.load_plugin method:
def load_plugin(self) -> Any:
plugin_path = self.plugin_info.location.parent
if plugin_path not in sys.path:
sys.path.append(plugin_path)
plugin_classes = self.plugin_info.load_plugin_classes(self._base_module, self._base_class)
if len(plugin_classes) != 1:
raise PluginNotFoundException(f'Found more that one plugin for {self._base_class}.')
_, clazz = plugin_classes[0]
return clazz(self._config)
like so (filter out the plugin's classes returned by PluginInfo.load_plugin_classes method):
def load_plugin(self) -> Any:
plugin_path = self.plugin_info.location.parent
if plugin_path not in sys.path:
sys.path.append(plugin_path)
module_name = self._base_module + '.' + self.plugin_info.module
plugin_classes = self.plugin_info.load_plugin_classes(self._base_module, self._base_class)
# Filter out the plugin's classes so that only the classes which were defined in a
# backend's module file are left
plugin_classes = [p_c for p_c in plugin_classes if p_c[1].__module__ == module_name]
if len(plugin_classes) != 1:
raise PluginNotFoundException(f'Found more that one plugin for {self._base_class}.')
_, clazz = plugin_classes[0]
return clazz(self._config)
after this only the classes defined in a backend module file (which will be derived from baseclass) will be considered as the possible classes of the backend and not those which will be just imported in the backend module.
Hipchat is no longer around, so there would be no fix for this.
I am...
I am running...
Issue description
ErrBot fails to start with HipChat backend.
Steps to reproduce
Start ErrBot with HipChat backend (no actual HipChat server is required to reproduce this error).
Additional info
When I try to start ErrBot it fails with the following error message:
The cause of this problem seems to be that the HipchatBackend class (in hipchat.py backend module file) is derived from XMPPBackend class and not directly from the errbot.core.ErrBot class, so the PluginInfo.load_plugin_classes(self, base_module_name, baseclass) method returns the following for the HipChat module:
[('HipchatBackend', <class 'errbot.backends.hipchat.HipchatBackend'>), ('XMPPBackend', <class 'errbot.backends.xmpp.XMPPBackend'>)]