python-drafthorse icon indicating copy to clipboard operation
python-drafthorse copied to clipboard

TypeError: None is not of type <class 'str'>

Open PatrickDEissler opened this issue 4 months ago • 1 comments

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

PatrickDEissler avatar Jul 25 '25 12:07 PatrickDEissler

Ideas:

  • check if empty tags are allowed as per standard
  • use the strict parameter to disable type validation entirely, or at least allow the None type along with expected type

barredterra avatar Jul 25 '25 12:07 barredterra

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

raphaelm avatar Nov 27 '25 20:11 raphaelm