dapper91 / pydantic-xml

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

wrapped sub-elements serialization bug fixed #70

Closed dapper91 closed 1 year ago

dapper91 commented 1 year ago

This MR fixes the bug related to wrapped sub-elements serialization.

The model:

from pydantic_xml import BaseXmlModel, element, wrapped

class Company(BaseXmlModel):
    title: str = element()
    country: str = wrapped('address', element())
    city: str = wrapped('address', element())

model = Company(title='SpaceX', country='US', city='Hawthorne')

should be serialized as the xml document:

<Company>
  <title>SpaceX</title>
  <address>
    <country>US</country>
    <city>Hawthorne</city>
  </address>
</Company>

but wrapped element is duplicated:

<Company>
  <title>SpaceX</title>
  <address>
    <country>US</country>
  </address>
  <address>
    <city>Hawthorne</city>
  </address>
</Company>

fixes the issue https://github.com/dapper91/pydantic-xml/issues/63

codecov-commenter commented 1 year ago

Codecov Report

Merging #70 (1fdff14) into dev (a6d40e6) will increase coverage by 0.01%. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##              dev      #70      +/-   ##
==========================================
+ Coverage   93.11%   93.13%   +0.01%     
==========================================
  Files          23       23              
  Lines        1089     1092       +3     
==========================================
+ Hits         1014     1017       +3     
  Misses         75       75              
Flag Coverage Δ
unittests 93.13% <100.00%> (+0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pydantic_xml/element/element.py 99.39% <100.00%> (+<0.01%) :arrow_up:
pydantic_xml/serializers/factories/union.py 87.95% <100.00%> (+0.14%) :arrow_up: