RoundTripLoader causes exceptions with nested anchors

Issue #61 resolved
Tal Liron
created an issue

Python 2.7 using package version 0.12.13:

from ruamel import yaml

data = """
def1: &ANCHOR1
    key1: value1
def: &ANCHOR
    <<: *ANCHOR1
    key: value
value:
    <<: *ANCHOR
"""

# This fails
print yaml.load(data, Loader=yaml.RoundTripLoader)['value']

# This works
print yaml.load(data, Loader=yaml.SafeLoader)['value']

The failure is this exception:

Traceback (most recent call last):
  File "yaml.py", line 15, in <module>
    print yaml.load(data, Loader=yaml.RoundTripLoader)['value']
  File "local/lib/python2.7/site-packages/ruamel/yaml/comments.py", line 531, in __repr__
    return 'ordereddict(' + repr(list(self._items())) + ')'
  File "local/lib/python2.7/site-packages/ruamel/yaml/comments.py", line 634, in _items
    yield x, ordereddict.__getitem__(merged[1], x)
KeyError: 'key1'

Note that everything works fine with the SafeLoader.

Comments (1)

  1. Log in to comment