fix: honour exclude_defaults for link fields - #167
Open
simontaurus wants to merge 1 commit into
Open
simontaurus wants to merge 1 commit into
simontaurus wants to merge 1 commit into
Conversation
- a link left at the IRI its field declares is now omitted; the value is routed out of the field pydantic compares, so __link_defaults__ decides - v1 dict() re-added an unset link as None past exclude_defaults, exclude_unset and exclude, which v2 already filtered - to_json re-added link IRIs after the dump had excluded them
Contributor
Release previewNo version bump from the current commits (stays at Changelog preview (truncated)Preview via python-semantic-release and conventional commits. |
Contributor
📊 Benchmark ResultsClick to see benchmark comparisonThreshold: 1.3x (30% slower triggers a regression warning) Note: Benchmarks are informational only and won't fail the build. 💡 Tip: Download the |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Follow-up to #166, which surfaced this while testing
.json(exclude_none=True, exclude_defaults=True, indent=2).Declaring a default IRI for a link already works and is already seeded at construction (
__link_defaults__,src/oold/model/_descriptor.py:133):But
exclude_defaults=Truenever omitted it. A link value is routed out of the field pydantic validates, so that field always sits atNoneand pydantic's comparison answers "not a default" for every link, set or not.Changes:
_matches_link_defaultcompares the stored IRI(s) against__link_defaults__, reading both sides as lists so a to-one default seeded into a to-many link still matchesdict()override, and into_json, which re-added link IRIs after the dump had excluded themdict()also wrote an unset link back asNonepastexclude_defaults,exclude_unsetandexclude={...}; v2 already filtered those and v1 legacy omits them, so this is a parity fix in both directionstests/test_serialization.py, parametrised over both versions, importing the descriptor bindings directly because the legacy bindings do not record link defaults at all740 passed under both bindings.