Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Make YAML serialization deterministic - #203

#203
Open
olafmersmann wants to merge 3 commits into
mainOpenOptimizationOrg/OPL:mainfrom
feat-canonical_yamlOpenOptimizationOrg/OPL:feat-canonical_yamlCopy head branch name to clipboard
Open

feat: Make YAML serialization deterministic#203
olafmersmann wants to merge 3 commits into
mainOpenOptimizationOrg/OPL:mainfrom
feat-canonical_yamlOpenOptimizationOrg/OPL:feat-canonical_yamlCopy head branch name to clipboard

Conversation

@olafmersmann

Copy link
Copy Markdown
Collaborator

pydantic-yaml serializes model fields via model_dump_json() but set iteration is order depends on hash randomization, which is randomized per interpreter process, so to_yaml_str() produced a different ordering of these fields on every run even when the underlying data was unchanged.

Add a _CanonicalMixin used by new CanonicalModel/CanonicalRootModel base classes in schema.py. Each defines a single model_serializer(mode="wrap") that inspects a model's actual field values at dump time and sorts any that are a set into a list.

Fixes #202

olafmersmann and others added 3 commits July 28, 2026 15:38
pydantic-yaml serializes model fields via model_dump_json() but set iteration 
is order depends on hash randomization, which is randomized per interpreter
process, so `to_yaml_str()` produced a different ordering of these fields
on every run even when the underlying data was unchanged.

Add a `_CanonicalMixin` used by new `CanonicalModel`/`CanonicalRootModel`
base classes in schema.py. Each defines a single model_serializer(mode="wrap")
that inspects a model's actual field values at dump time and sorts any that
are a `set` into a list.
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.

Canonical form for YAML

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.