Skip to content

fix: write the top-level object's metadata in rune_serialize - #70

Merged
plamen-neykov merged 1 commit into
mainfrom
fix-top-level-metadata
Nov 10, 2026
Merged

plamen-neykov merged 1 commit into
mainfrom
fix-top-level-metadata

Conversation

@dschwartznyc

Copy link
Copy Markdown
Contributor

Closes #64.

Problem

The top-level object's metadata, such as @key or @key:external, was read and kept on the object, but rune_serialize didn't write it. The same metadata on an object held in a field was written.

An object's metadata is written by the serializer of the field that holds it. The top-level object isn't held in a field, and rune_serialize only added @type, @model and @version to the top level.

For example, reading {"@key": "k1", "party": {"name": "A"}} into a Trade and writing it again gave {"@type": ..., "@model": ..., "@version": ..., "party": {"name": "A"}}, without "@key": "k1".

Change

rune_serialize adds the object's own metadata to the top level, after @version is set:

root_meta |= self.serialise_meta()  # type: ignore

The # type: ignore matches the root_meta line above it.

New test/test_top_level_metadata.py, 8 tests, using the classes rune-python-generator produces for a type with [metadata key], an attribute of such a type, and a type without metadata. It covers @key, @key:external, both together, a top-level key alongside a key on a field, writing with validation on, @type, @model and @Version still being written, an object without metadata, and writing twice.

Testing

  • test/test_top_level_metadata.py: all 8 pass. Run against main without this change, the 5 tests that check a top-level key is written fail, which confirms they test the bug.
  • Full suite in a clean environment (pip install .[dev] plus pytest, pytest-cov and pytest-mock, as in run-tests.yml): 431 passed, 20 skipped. The skips are the tests that need the generated serialization package or a CDM package.
  • ruff check passes on base_data_class.py.

Note

Java writes @key:external on the top-level object, but leaves out an @key that nothing refers to, as it does for any @key. Python doesn't leave out unreferenced keys anywhere (#65), so this change writes the top-level @key as it was read.

@github-actions

Copy link
Copy Markdown

Test Results

451 tests  +8   431 ✅ +8   1s ⏱️ -1s
  1 suites ±0    20 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 85442c8. ± Comparison against base commit 263677c.

@plamen-neykov plamen-neykov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good.

@plamen-neykov
plamen-neykov merged commit 6cd39ce into main Nov 10, 2026
6 checks passed
@plamen-neykov
plamen-neykov deleted the fix-top-level-metadata branch November 10, 2026 21:39
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.

Serialization loses top level metadata

3 participants