Menu

#463 IndexError when using .insert() after calling 'merge' property

closed
nobody
None
minor
bug
2023-05-25
2023-05-24
No

Bug appears when calling CommentedMap.insert() after calling the merge property. See below.

The bug is present in latest version but I could trace its appearance starting in 0.17.24

from ruamel.yaml import YAML

yaml = YAML()

yaml_str = """\
    first_name: Art
    """

data = yaml.load(yaml_str)
_ = data.merge    # causes the bug to appear (as the property sets ._yaml_merge)

data.insert(0, "some_key", "test")    # <- raises 
File ~/.pyenv/versions/3.8.6/envs/.../lib/python3.8/site-packages/ruamel/yaml/comments.py:802, in CommentedMap.insert(self, pos, key, value, comment)
    800     del self[key]
    801 keys = [k for k in self.keys() if k in self._ok]
--> 802 ma0 = getattr(self, merge_attrib, [[-1]])[0]
    803 merge_pos = ma0[0]
    804 if merge_pos >= 0:

IndexError: list index out of range

Discussion

  • Anthon van der Neut

    Thanks for reporting, This should be fixed in 0.17.27

     
  • Anthon van der Neut

    • status: open --> resolved
     
  • Anthon van der Neut

    • status: resolved --> closed
     
  • Anthon van der Neut

    0.17.27 has been released with the fix for this

     

Log in to post a comment.