A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance

Hello, In our app, we’ve modeled our schema using inheritance introduced in iOS 26.0, and we’re implementing SwiftData History to re-fetch models only when necessary.

@Model public class Transaction {
    @Attribute(.preserveValueOnDeletion)
    public var date: Date = Date()
    public var amount: Double = 0
    public var memo: String?
}

@Model public final class Spending: Transaction {
    public var installmentIndex: Int = 1
    public var installment: Int = 1
    public var installmentID: UUID?
}

If data has been deleted from database, we need to check a date property to determine whether to re-fetch datas.

To do this, we added the preserveValueOnDeletion attribute to date property so we could retrieve it from the History tombstone value.

However, after adding this attribute, a crash occurs. There is a console log

Could not cast value of type 'Swift.ReferenceWritableKeyPath<Shared.ModelSchemaV5.Transaction, Foundation.Date>' (0x106bf8328) to 'Swift.PartialKeyPath<Shared.ModelSchemaV5.Spending>' (0x1094f21d8).

and error log attached

I also tried this in the recent SampleTrip app, and fetching all history after a deletion causes the same crash. Is this issue currently being worked on or under investigation?

Do you see the issue happening on iOS 26.2 beta? If yes, would you mind to file a feedback report for us and share your report ID here? Thanks!

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance
 
 
Q