fix: prevent HistoryItemContent orphaning during duplicate resolution#1387
Open
Project-A-E-G-I-S wants to merge 1 commit into
Open
fix: prevent HistoryItemContent orphaning during duplicate resolution#1387Project-A-E-G-I-S wants to merge 1 commit into
Project-A-E-G-I-S wants to merge 1 commit into
Conversation
When a duplicate clipboard item was detected, History.add() replaced the incoming item's contents with the existing item's contents without cleanup. The original contents (already persisted to SwiftData) were orphaned as rows with item == nil. Additionally, cascade-deleting the existing item would delete content objects now shared with the replacement. Fix: - Delete incoming item's contents from store before replacement - Detach existing item's contents before cascade deletion - Both scoped to the isModified(item) == nil block (contents transfer path) Test: testDuplicateDoesNotOrphanContents verifies exact 1:1 content-to-item ratio after duplicate merge. Closes p0deje#1368
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
Fixes a bug where adding a duplicate clipboard item could leave orphaned
HistoryItemContentrows in the SwiftData store withitem == nil, and cascade deletion of the existing item could delete content objects shared with the replacement item.Root Cause
In
History.add(_:)(Maccy/Observables/History.swift:147-163), when a duplicate was detected:Fix
existingHistoryItem.contents = []) before cascade deletion (prevents shared content from being wiped)if isModified(item) == nil, so they only run when contents are actually transferredTesting
Added
testDuplicateDoesNotOrphanContentswhich verifies:HistoryItemContentrow exists after duplicate mergeitemreferenceCloses #1368