inveniosoftware / dojson

Simple pythonic JSON to JSON converter.
https://dojson.readthedocs.io
Other
10 stars 29 forks source link

GroupableOrderedDict riases KeyError on empty values #150

Closed egabancho closed 8 years ago

egabancho commented 8 years ago
>>> from dojson.contrib.marc21.utils import create_record
>>> xml = '<record><datafield tag="037" ind1=" " ind2=" "></datafield></record>'
>>> d = create_record(xml)
>>> d
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/collections.py", line 173, in __repr__
    return '%s(%r)' % (self.__class__.__name__, self.items())
  File "/opt/cds/lib/python2.7/site-packages/dojson/utils.py", line 358, in items
    return tuple(self.iteritems(with_order, repeated))
  File "/opt/cds/lib/python2.7/site-packages/dojson/utils.py", line 369, in iteritems
    yield key, value[0]
  File "/opt/cds/lib/python2.7/site-packages/dojson/utils.py", line 286, in __getitem__
    item = OrderedDict.__getitem__(self, key)
KeyError: 0
>>> d['037__']
GroupableOrderedDict((('__order__', ()),))