Whole file

martinblech/xmltodict

The author described this change as fix(unparse): serialize None text/attrs as empty values (fixes #401). It counts as a record because the checks below fail on the code as it stood at f7d76c96f and pass on aa165113b, with nothing else changed between the two runs.

Fix saved2026-02-15
Sharing licenceMIT · LICENSE
Change size+8 3

What the code was meant to do, written into the code itself as a save note

fix(unparse): serialize None text/attrs as empty values (fixes #401)

The change

493493 children = []
494494 for ik, iv in v.items():
495495 if ik == cdata_key:
496- cdata = _convert_value_to_string(iv)
496+ if iv is None:
497+ cdata = None
498+ else:
499+ cdata = _convert_value_to_string(iv)
497500 continue
498501 if isinstance(ik, str) and ik.startswith(attr_prefix):
499502 ik = _process_namespace(ik, namespaces, namespace_separator,
502505 for k, v in iv.items():
503506 _validate_name(k, "attribute")
504507 attr = 'xmlns{}'.format(f':{k}' if k else '')
505- attrs[attr] = str(v)
508+ attrs[attr] = '' if v is None else str(v)
506509 continue
507- if not isinstance(iv, str):
510+ if iv is None:
511+ iv = ''
512+ elif not isinstance(iv, str):
508513 iv = str(iv)
509514 attr_name = ik[len(attr_prefix) :]
510515 _validate_name(attr_name, "attribute")

The check that tells the two apart

failpass·tests/test_dicttoxml.py::test_none_attribute_serializes_as_empty_string
failpass·tests/test_dicttoxml.py::test_none_text_with_short_empty_elements_and_attributes

Check file tests/test_dicttoxml.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf7d76c96fc0141238947abcc5fa925d3ffd9eb78
Broken version dated2025-10-27
Modulexmltodict
Units changed_emit
Fingerprintea9a70046e200315
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in martinblech/xmltodict