Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with optional fields with flag --ouput pydantic vs dataclass #28

Open
lionpeloux opened this issue May 25, 2024 · 0 comments
Open

Comments

@lionpeloux
Copy link

Hi @tefra,

Your package looks promising.
I encountered an issue while generating models from a xsd.
The dataclass models work fine while the pydantic models don't.

It seems to me that there is a problem in how optional fields are generated (only for --output pydantic)
You'll see the difference in the following image (for the same initial DPEv2.2.xsd file), where fields where tagged "optional" in the dataclass version while they were not in the pydantic. Maybe this is due to the fact that these fields are grouped in a <xsd:all> tag ?!

dataclass (left) vs  pydantic (right)

I generated the models from the same xsd like this :

xsdata DPEv2.2.xsd --package models_dataclass
xsdata DPEv2.2.xsd --output pydantic --package models_pydantic

And run the following code on a sample xml file

# Uncomment to work on models_pydantic version
# from models_pydantic import Dpe
# from xsdata_pydantic.bindings import XmlParser

# Uncomment to work on models_dataclass version
from models_dataclass import Dpe
from xsdata.formats.dataclass.parsers import XmlParser

parser = XmlParser()
result = parser.parse("2344E0308327N.xml", Dpe)

murs = result.logement.enveloppe.mur_collection.mur
for mur in murs:
    print(mur.donnee_entree.surface_paroi_totale)

You'll find the example xsd and xml files here : mwe.zip

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

No branches or pull requests

1 participant