Skip to content

Pydantic 2.12 deprecated merge_field_infos #292

@Max-Hoek

Description

@Max-Hoek

Hi, in Pydantic 2.12 the merge_field_infos method was deprecated and its uses were removed.
Consequently XmlEntityInfo.merge_field_infos is never called, which breaks Annotated type annotations.

from pydantic_xml import BaseXmlModel, element
from pydantic_xml.fields import XmlEntityInfo
from typing import Annotated


class Model1(BaseXmlModel):
    value: int = element()


class Model2(BaseXmlModel):
    value: Annotated[int, ...] = element()


def main() -> None:
    # Works correctly
    assert isinstance(Model1.model_fields['value'], XmlEntityInfo)

    # Fails, the type is FieldInfo
    assert isinstance(Model2.model_fields['value'], XmlEntityInfo)


if __name__ == "__main__":
    main()

cpython-3.13.3
pydantic 2.12.0
pydantic-xml 2.17.3

Previously merge_field_infos was called in FieldInfo.from_annotation and FieldInfo.from_annotated_attribute.
Maybe XmlEntityInfo needs to override these methods now instead.
Alternatively, the deprecation message suggests opening an issue on the Pydantic issue tracker.

@dapper91 would you have a preference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions