File tree Expand file tree Collapse file tree
Sources/CoreDataRepository Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,11 +17,18 @@ extension CoreDataRepository {
1717 ) async -> Result < Model , CoreDataError > {
1818 await context. performInScratchPad ( schedule: . enqueued) { [ context] scratchPad in
1919 let object = Model . ManagedModel ( context: scratchPad)
20+ let tempObjectId = object. objectID
2021 try item. updating ( managed: object)
2122 try scratchPad. save ( )
2223 try context. performAndWait {
2324 context. transactionAuthor = transactionAuthor
24- try context. save ( )
25+ do {
26+ try context. save ( )
27+ } catch {
28+ let parentContextObject = context. object ( with: tempObjectId)
29+ context. delete ( parentContextObject)
30+ throw error
31+ }
2532 context. transactionAuthor = nil
2633 }
2734 try scratchPad. obtainPermanentIDs ( for: [ object] )
Original file line number Diff line number Diff line change @@ -21,19 +21,16 @@ extension NSManagedObjectContext {
2121 } catch let error as CoreDataError {
2222 await scratchPad. perform {
2323 scratchPad. rollback ( )
24- scratchPad. parent? . rollback ( )
2524 }
2625 return . failure( error)
2726 } catch let error as CocoaError {
2827 await scratchPad. perform {
2928 scratchPad. rollback ( )
30- scratchPad. parent? . rollback ( )
3129 }
3230 return . failure( . cocoa( error) )
3331 } catch let error as NSError {
3432 await scratchPad. perform {
3533 scratchPad. rollback ( )
36- scratchPad. parent? . rollback ( )
3734 }
3835 return . failure( CoreDataError . unknown ( error) )
3936 }
You can’t perform that action at this time.
0 commit comments