Whole file
martinblech/xmltodict
The author described this change as “fix(namespaces): attach `@xmlns` to declaring element when process_namespaces=True”. It counts as a record because the check below fails on the code as it stood at 75a17701d and passes on f0322e578, with nothing else changed between the two runs.
Projectmartinblech/xmltodict
Fix saved2025-09-12
Sharing licenceMIT · LICENSE
Change size+3 −1
What the code was meant to do, written into the code itself as a save note
fix(namespaces): attach `@xmlns` to declaring element when process_namespaces=True
The change
| 85 | 85 | def startElement(self, full_name, attrs): | |
| 86 | 86 | name = self._build_name(full_name) | |
| 87 | 87 | attrs = self._attrs_to_dict(attrs) | |
| 88 | - | if attrs and self.namespace_declarations: | |
| 88 | + | if self.namespace_declarations: | |
| 89 | + | if not attrs: | |
| 90 | + | attrs = self.dict_constructor() | |
| 89 | 91 | attrs['xmlns'] = self.namespace_declarations | |
| 90 | 92 | self.namespace_declarations = self.dict_constructor() | |
| 91 | 93 | self.path.append((name, attrs or None)) |
The check that tells the two apart
fail→pass·tests/test_xmltodict.py::XMLToDictTestCase::test_namespace_on_root_without_other_attrs
Check file tests/test_xmltodict.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 it75a17701db20d5d3ec2ea1f6c901cf2211011eb5
Broken version dated2025-09-08
Modulexmltodict
Units changed_DictSAXHandler
Fingerprint728a0b23b6be471c
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
- 2026-02-15fix(unparse): serialize None text/attrs as empty values (fixes #401)
- 2025-09-17fix: allow DOCTYPE with disable_entities=True (default)
- 2025-09-16fix: fail closed when entities disabled
- 2025-09-16fix: validate XML comments
- 2025-09-12fix(unparse): handle non-string `#text` with attributes; unify value conversion
- 2025-09-12fix(unparse): skip empty lists to keep pretty/compact outputs consistent