Repository navigation
fix: write whole lists in rune_serialize instead of raising Attribute… - #71
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Write whole lists in
rune_serializeinstead of raisingAttributeErrorFixes bug 4 in #42.
Problem
rune_serialize()failed on any list attribute whose serializer wraps the whole list:The generator puts the serializer and validator around the whole list for a list attribute with metadata, such as
parties Party (0..*)wherePartyhas[metadata key], and for every list attribute in a generated bundle. The list then reachesserialisein a single call, and was treated as one object. Reading the same data already worked, becausedeserializehandles a list.Change
In
src/rune/runtime/metadata.py, the serializers for complex types, basic types with metadata, and enums with metadata:NoneasNone;{"@ref": ...};return_type=Any, since they can now return a list.For an enum with metadata, a single value is still written with
handler(obj.enum_instance), as onmain. The handler of a list attribute serializes the list's type, so it can't be used for one item; each item in a list writes its enum value directly.New
test/test_list_cardinality_serialise.py, 9 tests, using the classesrune-python-generatorproduces, in the form used in a generated bundle. It covers lists of objects, objects with keys, strings with metadata and enums with metadata, an empty list, an absent list, a list built in Python, an item of a subtype written with its@type, and a list of references written back as references.Testing
test/test_list_cardinality_serialise.py: all 9 pass. Run againstmainwithout this change, 8 of the 9 fail.pip install .[dev]pluspytest,pytest-covandpytest-mock, as inrun-tests.yml): 440 passed, 20 skipped. The skips are the tests that need the generatedserializationpackage or a CDM package.serializationpackage generated fromrune-common's round-trip suite installed,test/serializer-round-trip/test_metascheme.py::test_enum_listnow passes. The 2 remaining failures there, intest_extension.py, are the subtype problem in Assigning an object to an attribute should store a copy that keeps its actual type #66.ruff checkpasses onmetadata.py.Notes
model_dump(), a single enum with metadata gives anEnummember in@data, and an item in a list gives the enum's value as a string. JSON output is the same for both.@typeformat needsfix-match-java-choice-serializationas well, and isn't tested here. Both branches changeComplexTypeMetaDataMixin.serialise, so whichever merges second needs that function merged by hand.