← Back to team overview

python-jenkins-developers team mailing list archive

[Bug 1860891] [NEW] get_plugins() fails with multi-key error when duplicate plugin exists

 

Public bug reported:

Version: 1.0.2

Issue: get_plugins() fails with multi-key error when duplicate plugin
exists

Description:

* When calling get_plugins() on a Jenkins with a duplicate plugin, the method throws KeyError exception. 
* For example, say a Jenkins host has 2 different versions of plugin P1 with shortName as 'short-plugin-name' and longName as 'Long Plugin Name' installed.
* get_plugins() will throw the following error:
Traceback (most recent call last):
  File "plugin_dump_util.py", line 76, in <module>
    get_master_jenkins_plugins_info()
  File "plugin_dump_util.py", line 40, in get_master_jenkins_plugins_info
    get_plugin_info_of_each_jm(jenkins_admin_server_obj, jenkins_master_url)
  File "plugin_dump_util.py", line 47, in get_plugin_info_of_each_jm
    jenkins_master_plugin_api_dump = jenkins_admin_server_obj.get_plugins()
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 939, in get_plugins
    plugins_data[keys] = plugins.Plugin(**plugin_data)
  File "/usr/local/lib/python3.8/site-packages/multi_key_dict.py", line 118, in __setitem__
    raise KeyError(', '.join(str(key) for key in keys))
KeyError: 'short-plugin-name, Long Plugin Name'


Analysis:
* Upon checking the code I see that the method returns a multi-key dictionary:
plugins_data = multi_key_dict.multi_key_dict()
        for plugin_data in plugins_info_json['plugins']:
            keys = (str(plugin_data['shortName']), str(plugin_data['longName']))
            plugins_data[keys] = plugins.Plugin(**plugin_data)

        return plugins_data
* The key for which is generated using shortName AND longName.
* When calling get_plugins(), the multi-key dictionary could not be generated as the second time it encounters the plugin with same shortName and longName resulting in the KeyError.

Recommendation:
* It feels more appropriate to have shortName/longName AND version as a dictionary.

** Affects: python-jenkins
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1860891

Title:
  get_plugins() fails with multi-key error when duplicate plugin exists

Status in Python Jenkins:
  New

Bug description:
  Version: 1.0.2

  Issue: get_plugins() fails with multi-key error when duplicate plugin
  exists

  Description:

  * When calling get_plugins() on a Jenkins with a duplicate plugin, the method throws KeyError exception. 
  * For example, say a Jenkins host has 2 different versions of plugin P1 with shortName as 'short-plugin-name' and longName as 'Long Plugin Name' installed.
  * get_plugins() will throw the following error:
  Traceback (most recent call last):
    File "plugin_dump_util.py", line 76, in <module>
      get_master_jenkins_plugins_info()
    File "plugin_dump_util.py", line 40, in get_master_jenkins_plugins_info
      get_plugin_info_of_each_jm(jenkins_admin_server_obj, jenkins_master_url)
    File "plugin_dump_util.py", line 47, in get_plugin_info_of_each_jm
      jenkins_master_plugin_api_dump = jenkins_admin_server_obj.get_plugins()
    File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 939, in get_plugins
      plugins_data[keys] = plugins.Plugin(**plugin_data)
    File "/usr/local/lib/python3.8/site-packages/multi_key_dict.py", line 118, in __setitem__
      raise KeyError(', '.join(str(key) for key in keys))
  KeyError: 'short-plugin-name, Long Plugin Name'

  
  Analysis:
  * Upon checking the code I see that the method returns a multi-key dictionary:
  plugins_data = multi_key_dict.multi_key_dict()
          for plugin_data in plugins_info_json['plugins']:
              keys = (str(plugin_data['shortName']), str(plugin_data['longName']))
              plugins_data[keys] = plugins.Plugin(**plugin_data)

          return plugins_data
  * The key for which is generated using shortName AND longName.
  * When calling get_plugins(), the multi-key dictionary could not be generated as the second time it encounters the plugin with same shortName and longName resulting in the KeyError.

  Recommendation:
  * It feels more appropriate to have shortName/longName AND version as a dictionary.

To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1860891/+subscriptions