Repository navigation
fix: DetachedDocument.toMap() must also preserve property insertion order - #6530
Conversation
…rder Follow-up to PR #6500 (issue #6472): that PR fixed the keys()/values() index-misalignment for MutableDocument by switching its toMap(boolean) from a plain HashMap to a LinkedHashMap, but DetachedDocument.toMap(boolean) had the exact same bug and was left unfixed - it also copied into a plain HashMap while its getPropertyNames() returns the same LinkedHashMap-backed map's keySet(). Document.detach() is a common pattern for handing documents outside a transaction, so keys()/values() on a detached document could still disagree by index. Switch DetachedDocument.toMap(boolean) to LinkedHashMap as well, matching MutableDocument and ImmutableDocument. Confirmed the added regression tests fail against the pre-fix code (order came back scrambled, e.g. [name, country, city, age, email] instead of insertion order) and pass with the fix.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ -6.55% coverage variation |
| Diff coverage | ✅ 100.00% diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (c751bca) 163958 130992 79.89% Head commit (0f245e9) 196345 (+32387) 144014 (+13022) 73.35% (-6.55%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6530) 1 1 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewClean, minimal, well-targeted fix — matches the pattern already used in Correctness
Tests
Minor / nit
No security, performance, or dependency concerns — this only changes the concrete Nice catch closing the gap left by the post-merge review on #6500. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6530 +/- ##
==========================================
- Coverage 71.19% 71.17% -0.02%
==========================================
Files 1866 1866
Lines 163958 163958
Branches 34629 34629
==========================================
- Hits 116724 116694 -30
- Misses 33007 33030 +23
- Partials 14227 14234 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Problem
PR #6500 (issue #6472) fixed
keys()/values()index-misalignment forDocumentby:SQLMethodValuesusedocument.toMap(false)instead oftoMap().MutableDocument.toMap(boolean)from a plainHashMapto aLinkedHashMap, so its iteration order matchesgetPropertyNames()(both derived from the same insertion-orderedmapfield).The post-merge review caught that
DetachedDocumenthas the exact same bug and was left unfixed:Document.detach()is a common pattern for handing documents outside a transaction, sodetached.keys()/detached.values()(or plaintoMap(false)) could still disagree by index for a detached document with 3+ properties.Fix
Switch
DetachedDocument.toMap(boolean)to build aLinkedHashMap, matchingMutableDocumentandImmutableDocument(which already usedLinkedHashMap).Tests
DocumentTest.detachedDocumentToMapPreservesPropertyInsertionOrder: assertstoMap(false)key/value order matchesgetPropertyNames()on a detached document with 5 properties.SQLMethodValuesTest.keysAndValuesAreIndexAlignedOnDetachedDocument: assertskeys()[i]/values()[i]correspondence via the SQL methods, on a detached document.Confirmed both new tests fail against the pre-fix code (property order came back scrambled, e.g.
[name, country, city, age, email]instead of insertion order[name, age, city, country, email]) and pass with the fix.Fixes the remaining part of #6472 not covered by #6500.