Skip to content

Commit ab6b1d9

Browse files
committed
Ensure contexts are reset and rollback when transaction is cancelled before exiting withTransaction
feature/transactions
1 parent 46cb5c9 commit ab6b1d9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Sources/CoreDataRepository/CoreDataRepository.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public final class CoreDataRepository: @unchecked Sendable {
7070
return result
7171
}
7272
try scratchPad.performAndWait {
73-
guard scratchPad.hasChanges, !transaction.canceled else {
73+
guard scratchPad.hasChanges else {
74+
return
75+
}
76+
guard !transaction.canceled else {
77+
scratchPad.reset()
7478
return
7579
}
7680
do {
@@ -81,7 +85,11 @@ public final class CoreDataRepository: @unchecked Sendable {
8185
}
8286
}
8387
try context.performAndWait {
84-
guard context.hasChanges, !transaction.canceled else {
88+
guard context.hasChanges else {
89+
return
90+
}
91+
guard !transaction.canceled else {
92+
context.rollback()
8593
return
8694
}
8795
context.transactionAuthor = transactionAuthor

0 commit comments

Comments
 (0)