dapper91 / pydantic-xml

python xml for humans
https://pydantic-xml.readthedocs.io
The Unlicense
155 stars 16 forks source link

Feature request: line numbers in validation errors #81

Closed bjones1 closed 9 months ago

bjones1 commented 1 year ago

Would it be possible to pydantic-xml to output the line number in the XML source where a validation error occurred? For complex structures, this would help quite a bit.

For example:

from textwrap import dedent
from typing import List
from pydantic_xml import BaseXmlModel, attr, element

class Company(BaseXmlModel):
    website: List[str] = element()
    foo: int = element()

print(Company.from_xml(dedent(
    """
    <Company>
        <website>http://www.spacex.com</website>
        <website>http://www.spacey.com</website>
        <website>http://www.spacez.com</website>
        <acfoo>This is not a number.</foo>
    </Company>
    """
)))

produces

pydantic.error_wrappers.ValidationError: 1 validation error for Company
foo
  value is not a valid integer (type=type_error.integer)

I'd like to see something like:

pydantic.error_wrappers.ValidationError: 1 validation error for Company
<input>, line 5: foo
  value is not a valid integer (type=type_error.integer)
dapper91 commented 9 months ago

implemented in version 2.7.0.

bjones1 commented 9 months ago

Wow, very exciting! Thanks!!!