amazon-ion / ion-python

A Python implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
260 stars 51 forks source link

Empty String Key in Dict Fails Encoding #140

Closed bryanhelmig closed 3 years ago

bryanhelmig commented 3 years ago

Reproduction case:

import amazon.ion.simpleion as ion
ion.dumps({'': ''})

Gives you:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/simpleion.py", line 283, in dumps
    dump(obj, ion_buffer, imports=imports, sequence_as_stream=sequence_as_stream, binary=binary, skipkeys=skipkeys,
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/simpleion.py", line 158, in dump
    _dump(obj, writer, from_type)
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/simpleion.py", line 220, in _dump
    _dump(val, writer, from_type, field, in_struct=True, depth=depth+1)
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/simpleion.py", line 231, in _dump
    writer.send(event)
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer.py", line 150, in blocking_writer
    for result_event in _drain(writer, ion_event):
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer.py", line 129, in _drain
    result_event = writer.send(ion_event)
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer.py", line 111, in writer_trampoline
    trans = trans.delegate.send(Transition(ion_event, trans.delegate))
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer_binary.py", line 214, in _managed_binary_writer_coroutine
    write_event = value_writer.send(ion_event)
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer.py", line 111, in writer_trampoline
    trans = trans.delegate.send(Transition(ion_event, trans.delegate))
  File "/code/ion-is-cool/.venv/lib/python3.8/site-packages/amazon/ion/writer_binary_raw.py", line 353, in _raw_writer_coroutine
    _write_varuint(sid_buffer, ion_event.field_name.sid)  # Write the field name's symbol ID.
AttributeError: 'str' object has no attribute 'sid'
cheqianh commented 3 years ago

Thanks for letting us know the issue, #141 fixed it.

Feel free to reopen the issue if you have any further questions.

bryanhelmig commented 3 years ago

Thanks @cheqianh -- appreciate you snagging this! I hope you have a great weekend!