Skip to content

key_rewrites in RewrittenYaml does not work #3478

@ErikOrjehag

Description

@ErikOrjehag

key_rewrites for RewrittenYaml doesn't work in galactic with python 3.8.5.

I get this error:

  File "/opt/ros/galactic/lib/python3.8/site-packages/nav2_common/launch/rewritten_yaml.py", line 90, in perform
    self.substitute_keys(data, keys_rewrites)
  File "/opt/ros/galactic/lib/python3.8/site-packages/nav2_common/launch/rewritten_yaml.py", line 137, in substitute_keys
    for key, val in yaml.items():
RuntimeError: dictionary keys changed during iteration

Here is the function:
https://github.com/ros-planning/navigation2/blob/2de3f92c0f476de4bda21d1fc5268657b499b258/nav2_common/nav2_common/launch/rewritten_yaml.py#L135-L142

Another thing I noticed while looking at this is that we should recuse even if key is not in key_rewrites? And also substitute keys if the value is not a dict? Maybe this could work better:

    def substitute_keys(self, yaml, key_rewrites):
        if len(key_rewrites) != 0:
            for key in list(yaml.keys()):
                val = yaml[key]
                if key in key_rewrites:
                    new_key = key_rewrites[key]
                    yaml[new_key] = yaml[key]
                    del yaml[key]
                if isinstance(val, dict):
                    self.substitute_keys(val, key_rewrites)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions