Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pydantic_xml/serializers/factories/heterogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pydantic_xml import errors, utils
from pydantic_xml.element import XmlElementReader, XmlElementWriter
from pydantic_xml.serializers.factories import primitive
from pydantic_xml.serializers.serializer import TYPE_FAMILY, SchemaTypeFamily, Serializer
from pydantic_xml.typedefs import EntityLocation, Location

Expand Down Expand Up @@ -109,6 +110,6 @@ def from_core_schema(schema: pcs.TupleSchema, ctx: Serializer.Context) -> Serial
elif ctx.entity_location is None:
return ElementSerializer.from_core_schema(schema, ctx)
elif ctx.entity_location is EntityLocation.ATTRIBUTE:
raise errors.ModelFieldError(ctx.model_name, ctx.field_name, "attributes of collection types are not supported")
return primitive.from_core_schema(pcs.StringSchema(type="str"), ctx)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it should work with any primitive type not only with a string one

else:
raise AssertionError("unreachable")
4 changes: 2 additions & 2 deletions pydantic_xml/serializers/factories/homogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pydantic_xml import errors, utils
from pydantic_xml.element import XmlElementReader, XmlElementWriter
from pydantic_xml.serializers.factories import primitive
from pydantic_xml.serializers.serializer import TYPE_FAMILY, SchemaTypeFamily, Serializer
from pydantic_xml.typedefs import EntityLocation, Location

Expand All @@ -27,7 +28,6 @@ def from_core_schema(cls, schema: HomogeneousCollectionTypeSchema, ctx: Serializ
if isinstance(items_schema, list):
assert len(items_schema) == 1, "unexpected items schema type"
items_schema = items_schema[0]

inner_serializer = Serializer.parse_core_schema(items_schema, ctx)

return cls(model_name, computed, inner_serializer)
Expand Down Expand Up @@ -134,6 +134,6 @@ def from_core_schema(schema: HomogeneousCollectionTypeSchema, ctx: Serializer.Co
elif ctx.entity_location is None:
return ElementSerializer.from_core_schema(schema, ctx)
elif ctx.entity_location is EntityLocation.ATTRIBUTE:
raise errors.ModelFieldError(ctx.model_name, ctx.field_name, "attributes of collection types are not supported")
return primitive.from_core_schema(pcs.StringSchema(type="str"), ctx)
else:
raise AssertionError("unreachable")