python-drafthorse
python-drafthorse copied to clipboard
TypeError: None is not of type <class 'str'>
If XML contains empty tags (self-closing, example: <ram:Content/>), the following error occurs:
doc = DrafthorseDocument.parse(xml_bytes, strict=False)
File "env/lib/python3.10/site-packages/drafthorse/models/elements.py", line 124, in parse
return cls().from_etree(root, strict)
File "env/lib/python3.10/site-packages/drafthorse/models/elements.py", line 114, in from_etree
getattr(self, name).from_etree(child, strict)
File "env/lib/python3.10/site-packages/drafthorse/models/elements.py", line 112, in from_etree
getattr(self, name).add_from_etree(child, strict)
File "env/lib/python3.10/site-packages/drafthorse/models/container.py", line 24, in add_from_etree
childel.from_etree(root, strict)
File "env/lib/python3.10/site-packages/drafthorse/models/elements.py", line 112, in from_etree
getattr(self, name).add_from_etree(child, strict)
File "env/lib/python3.10/site-packages/drafthorse/models/container.py", line 91, in add_from_etree
self.add(root.text)
File "env/lib/python3.10/site-packages/drafthorse/models/container.py", line 9, in add
raise TypeError("{} is not of type {}".format(item, self.child_type))
TypeError: None is not of type <class 'str'>
Version: drafthorse~=2025.1.0
Ideas:
- check if empty tags are allowed as per standard
- use the
strictparameter to disable type validation entirely, or at least allow theNonetype along with expected type
I don't think empty tags should be present in an invoice, as far as I understand, but I can't find the reference right now