fix(diff): match keyed lists by identifier instead of by position#92
Open
fix(diff): match keyed lists by identifier instead of by position#92
Conversation
added 2 commits
April 24, 2026 10:06
`inlined_as_list` collections of keyed objects were diffed positionally, so a mid-list remove produced a chain of shifted `Update` deltas plus a trailing `Remove`. On patch, the label resolver always picks the first matching id, so the Remove strikes the just-updated duplicate and silently clobbers any trailing change — a pure mid-list remove appears as a no-op, and removes combined with edits on later items lose the edits. When every element on both sides carries an identifier, match items by id: emit a clean `Remove` for items only in the source, an `Add` for items only in the target, and recurse on matched pairs. Lists of scalars or unkeyed objects keep the existing positional algorithm. Mappings were already key-matched. Regression test covers remove-from-middle combined with a trailing field update on a keyed list.
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.
Summary
inlined_as_listcollections of keyed objects were diffed positionally, so a mid-list remove produced shiftedUpdatedeltas plus a trailingRemove. On patch, the label resolver picks the first matching id, so theRemovestrikes the just-updated duplicate — a pure mid-list remove looks like a no-op, and removes combined with trailing edits lose the edits.Removefor items only in the source,Addfor items only in the target, and recurse on matched pairs. Lists of scalars or unkeyed objects keep the positional path; mappings were already key-matched.Test plan
cargo test -p linkml_runtime --test diff— newdiff_and_patch_remove_from_keyed_listregression (remove-from-middle plus trailing field update) + 9 existingcargo test --workspacecargo fmt --all -- --checkcargo clippy -p schemaview -p linkml_runtime -p linkml_tools -p linkml_runtime_python -p linkml_wasm --all-targets --all-features -- -D warnings --no-depscargo run -p linkml_runtime_python --bin stub_gen --features stubgen -- --check