ros / dynamic_reconfigure

BSD 3-Clause "New" or "Revised" License
48 stars 111 forks source link

decode_config fails for group data #109

Open krixkrix opened 6 years ago

krixkrix commented 6 years ago

The decode_config fails for group data. Can be reproduced by either:

  1. create a cfg that contains groups, then open rqt_reconfigure and save and reload the configuration.
  2. or: create a group with the attribute: type="collapse". Then open rqt_reconfigure and toggle the checkbox for that group.

in both cases the dynamic_reconfigure server fails this way:

[ERROR] [1527081248.063225] [/dynamic_tutorials]: Error processing request: 'list' object has no attribute 'items' ['Traceback (most recent call last):\n', ' File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py",line 625, in _handle_request\n response = convert_return_to_response(self.handler(request), self.response_class)\n', ' File "/opt/ros/kinetic/lib/python2.7/dist-packages/dynamic_reconfigure/server.py", line 135, in _set_callback\n return encode_config(self.update_configuration(decode_config(req.config, self.type.config_description)))\n', ' File "/opt/ros/kinetic/lib/python2.7/dist-packages/dynamic_reconfigure/encoding.py", line 312, in decode_config\n add_params(d[\'groups\'], description)\n', ' File "/opt/ros/kinetic/lib/python2.7/dist-packages/dynamic_reconfigure/encoding.py", line 308, in add_params\n for nr, dr in descr[\'groups\'].items():\n', "AttributeError: 'list' object has no attribute 'items'\n"]

I am not sure if it is the client side or server side who is wrong but the issue seems to be that the descr[\'groups\'] sometimes is a dict of dicts and sometimes a list of dicts, when iterated here

This change seems to solve the problem, but I don't think this is the right solution.

             for _n, g in group['groups'].items():
-                for _nr, dr in descr['groups'].items():
+                # descr['groups'] is sometimes
+                # - a list of dicts
+                # - a dict of dicts
+                groups = descr['groups']
+                if isinstance(descr['groups'], dict):
+                    groups = descr['groups'].values()
+
+                for dr in groups:
                     if dr['name'] == g['name']:
                         add_params(g, dr)

I will be happy to provide a pull request if someone can guide me on the expected encoding

MCFurry commented 2 years ago

Ahh we just ran into the same issue while implementing a reconfigure-client that tries to reconfigure a config including groups. But this still seems to be an issue present day?