Skip to content

Conversation

@dapper91
Copy link
Owner

@dapper91 dapper91 commented Jan 20, 2024

Union collection deserialization bug fixed.

Deserialization process gets stuck for List[Union] typed field because element index is not incremented if a validation error is raised.

Code example:

from typing import List, Union
from pydantic_xml import BaseXmlModel

class TestSubModel1(BaseXmlModel, tag='submodel1'):
    data: int

class TestSubModel2(BaseXmlModel, tag='submodel2'):
    data: float

class TestModel(BaseXmlModel, tag='model'):
    submodel: List[Union[TestSubModel1, TestSubModel2]]

xml = '''
    <model>
        <submodel2>a</submodel2>
        <submodel1>b</submodel1>
    </model>
'''

TestModel.from_xml(xml)

Fixes the issue.

sourceline was not being copied to snapshot which led to incorrect error message.
Deserialization proces gets stuck for List[Union] typed field because element index is not incremented if a validation error raised.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ee40d03) 91.78% compared to head (9fce737) 92.00%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #165      +/-   ##
==========================================
+ Coverage   91.78%   92.00%   +0.22%     
==========================================
  Files          26       26              
  Lines        1509     1514       +5     
==========================================
+ Hits         1385     1393       +8     
+ Misses        124      121       -3     
Flag Coverage Δ
unittests 92.00% <100.00%> (+0.22%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dapper91 dapper91 merged commit 0174621 into dev Jan 21, 2024
@dapper91 dapper91 mentioned this pull request Jan 21, 2024
Merged
@dapper91 dapper91 deleted the union-collection-deserialization-bugfix branch March 31, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants