From d55bd24ab204223130a068738e495961b971587e Mon Sep 17 00:00:00 2001 From: Hugo Hills Date: Wed, 14 Oct 2026 09:34:55 +0100 Subject: [PATCH] Fix serialisation with pydantic 2.14 by not passing info as index_key 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 #45 --- src/rune/runtime/base_data_class.py | 2 +- src/rune/runtime/metadata.py | 2 +- test/test_basic_types_with_meta.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rune/runtime/base_data_class.py b/src/rune/runtime/base_data_class.py index 47eab36..28f6d0d 100644 --- a/src/rune/runtime/base_data_class.py +++ b/src/rune/runtime/base_data_class.py @@ -107,7 +107,7 @@ def _unwrap_cow_inputs(cls, data: Any) -> Any: @model_serializer(mode='wrap') def _serialize_refs(self, serializer, info): '''should replace objects with refs while serializing''' - res = serializer(self, info) + res = serializer(self) refs = self._get_rune_refs_container() for property_nm, (key, ref_type) in refs.items(): res[property_nm] = {ref_type.rune_ref_tag: key} diff --git a/src/rune/runtime/metadata.py b/src/rune/runtime/metadata.py index 1f4067a..120c3d7 100644 --- a/src/rune/runtime/metadata.py +++ b/src/rune/runtime/metadata.py @@ -689,7 +689,7 @@ class EnumWithMetaMixin: def serialise(cls, obj, handler, info) -> dict: '''used as serialisation method with pydantic''' res = obj.serialise_meta() - res['@data'] = handler(obj.enum_instance, info) + res['@data'] = handler(obj.enum_instance) return res @classmethod diff --git a/test/test_basic_types_with_meta.py b/test/test_basic_types_with_meta.py index c33123f..7b8f3b6 100644 --- a/test/test_basic_types_with_meta.py +++ b/test/test_basic_types_with_meta.py @@ -356,6 +356,14 @@ def test_fail_create_constrained_num_model(): ConstrainedNumberModel(amount=NumberWithMeta(-1)) +def test_dump_annotated_enum_scheme(): + '''test the serialisation of an enum with meta''' + scheme_json = '{"enum_t":{"@scheme":"http://fpml.org","@data":"B"}}' + model = AnnotatedEnumModel.model_validate_json(scheme_json) + json_str = model.model_dump_json(exclude_unset=True) + assert json_str == scheme_json + + def test_annotated_enum_assignment(): '''test assignment''' model = AnnotatedEnumModel(enum_t=EnumType.B)