quandyfactory/dict2xml — Issue #2: Bug: dict value with unsupported type fails silently
Author: quandyfactory
Created: 2012-02-03 12:42:13+00:00
State: open

If you pass in a dict and one of the values is an unsupported type (e.g. a datetime object), the code doesn't raise an exception - it just passes silently over the value without adding it to the XML output. Here's an example that produces the issue:

>>> import dict2xml
>>> import datetime
>>> now = datetime.datetime.today()
>>> mydict = { 'name': 'Joe Blow', 'time': now }
>>> xml = dict2xml.dict2xml(mydict)
>>> print xml
Joe Blow
>>> # the 'time' key and its datetime value just silently disappeared

I propose the following fix:

* Raise an exception in `convert_dict()` and `convert_list()` if one of the elements is an unsupported type (currently, only `convert()` raises an exception).
* Include an optional parameter that will automatically convert datetimes into UTC strings in the XML output.
* Include an optional parameter that will automatically convert other unsupported types into their string representations.