Skip to content

Fix serialisation with pydantic 2.14 by not passing info as index_key - #46

Open
hugohills-regnosys wants to merge 1 commit into
finos:mainfrom
hugohills-regnosys:fix/pydantic-2.14-wrap-serializer
Open

hugohills-regnosys wants to merge 1 commit into
finos:mainfrom
hugohills-regnosys:fix/pydantic-2.14-wrap-serializer

Conversation

@hugohills-regnosys

Copy link
Copy Markdown

Fixes #45. With pydantic 2.14, serialising any BaseDataClass raised 'index_key' is expected to be an integer or a string, got 'SerializationInfo(...)'. The wrap serialisers in BaseDataClass._serialize_refs and EnumWithMetaMixin.serialise passed info as the handler's second positional argument, and that argument is index_key. Both now call the handler with the value only, which is the documented signature, so behaviour on earlier pydantic versions is unchanged.

Before this change, 15 tests in this suite failed on pydantic 2.14.1. The enum path had no serialisation test, so this adds test_dump_annotated_enum_scheme. It fails on 2.14.1 when only the enum call is left unfixed.

With this change, the suite gives 218 passed, 1 failed on both pydantic 2.14.1 and 2.13.4. That one failure, test_init_invalid_directory_or_module, also fails on main and is unrelated.

Separate from this PR: the pydantic>=2.10.3 floor in pyproject.toml is already broken. On 2.10.3 the package cannot be imported, on main as well as here, because ModelWrapValidatorHandler does not exist in that version.

🤖 Generated with Claude Code

The wrap serialisers in BaseDataClass and EnumWithMetaMixin passed
SerializationInfo as the handler's second positional argument, which is
index_key. pydantic 2.14 type-checks it and raises.

Fixes finos#45

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Serialisation fails with pydantic 2.14: wrap serialisers pass SerializationInfo as index_key

1 participant