from decimal import Decimal
from pydantic_xml import BaseXmlModel, element
class SomeModel(BaseXmlModel):
value: Decimal = element('Value')
Run / import the test.py file:
user@host:~$ python test.py
Traceback (most recent call last):
File "/home/user/pydantic-xml-bug/test.py", line 5, in <module>
class SomeModel(BaseXmlModel):
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/model.py", line 219, in __new__
cls.__build_serializer__()
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/model.py", line 279, in __build_serializer__
serializer = Serializer.parse_core_schema(
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/serializer.py", line 163, in parse_core_schema
return cls.select_serializer(schema, ctx)
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/serializer.py", line 220, in select_serializer
return factories.model.from_core_schema(schema, ctx)
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/factories/model.py", line 325, in from_core_schema
return ModelSerializer.from_core_schema(schema, ctx)
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/factories/model.py", line 60, in from_core_schema
fields_serializers[field_name] = Serializer.parse_core_schema(model_field['schema'], field_ctx)
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/serializer.py", line 162, in parse_core_schema
schema, ctx = cls.preprocess_schema(schema, ctx)
File "/home/user/pydantic-xml-bug/venv/lib/python3.10/site-packages/pydantic_xml/serializers/serializer.py", line 169, in preprocess_schema
raise ModelError(f"type {schema_type} is not supported")
pydantic_xml.errors.ModelError: type decimal is not supported
This works fine when using pydantic version 2.1.1.
Decimal fields break in the current beta release (
2.0.0b2
) when using pydantic version 2.2 (released on 2023-08-17).Steps to reproduce:
pydantic-xml==2.0.0b2
Create a
test.py
file with these contents:test.py
file:This works fine when using pydantic version 2.1.1.