Closed RiccardoNizzolo closed 4 days ago
@RiccardoNizzolo Hi,
That is breaking change in pydantic
itself, not pydantic-xml
. Starting from pydantic 2.0 it is not possible to get the field type from __fields__
map anymore.
If you want to analyze fields by yourself, you should analyze pydantic core schema:
>>> pprint(Company.__pydantic_core_schema__)
{'cls': <class '__main__.Company'>,
'config': {'title': 'Company'},
'custom_init': False,
'metadata': {...},
'ref': '__main__.Company:140461506687856',
'root_model': False,
'schema': {'computed_fields': [],
'fields': {'company_name': {'metadata': ...,
'schema': {'type': 'str'},
'type': 'model-field'},
'products': {'metadata': ...,
'schema': {'items_schema': {'cls': <class '__main__.Product'>,
'config': {'title': 'Product'},
'custom_init': False,
'metadata': ...,
'ref': '__main__.Product:140461504455808',
'root_model': False,
'schema': ...,
'type': 'model'},
'type': 'list'},
'type': 'model-field'}},
'model_name': 'Company',
'type': 'model-fields'},
'type': 'model'}
as you can see schema->fields->company_name->schema->type
is str, schema->fields->products->schema->items_schema->type
is model.
You can find more information here.
Hi I'm migrating a library from pydantic_xml 0.6 to the most recent version. I see that the subclasses are instantiated with different logic compared to the older version. Indeed running this script with different pydantic_xml version return different results. here the code:
output with version 0.6.0
output with version 2.10.0
Could this issue be a bug? How can I distinguish between a basic type that has no inner fields and a submodel that includes fields?