SwiftData crash: PersistentModel.keyPathToString(keypath:)

I'm distributing an iOS (17.4+) and visionOS (1.2+) app via TestFlight that's using SwiftData.

The most common crash by far is from SwiftData when deleting models from a context using a predicate (first snippet below), but so far I've been unable to reproduce it myself locally (second snippet below). I'm using SwiftData outside of SwiftUI views, via my own wrapper, and converting between my app models and SwiftData models.

Does anyone have any ideas how I could potentially narrow this issue down (or reproduce), or know of any similar issues?

Thanks! — Seb

do {
    try context.transaction { context in
        let predicate = #Predicate<PersistedFeed> {
            $0.id == id
        }
        do {
            try context.delete(model: PersistedFeed.self, where: predicate)
        } catch {
            // .. Omitted for brevity
        }
    }
} catch {
    // .. Omitted for brevity
}

Crash:

Thread 0 Crashed:
0   libswiftCore.dylib            	0x000000018dd558c0 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144)
1   SwiftData                     	0x000000022f7f323c static PersistentModel.keyPathToString(keypath:) + 1496 (DataUtilities.swift:0)
2   SwiftData                     	0x000000022f83312c PredicateExpressions.KeyPath.convert(state:) + 492 (FetchDescriptor.swift:394)
3   SwiftData                     	0x000000022f834a24 protocol witness for ConvertibleExpression.convert(state:) in conformance PredicateExpressions.KeyPath<A, B> + 16 (<compiler-generated>:0)
4   SwiftData                     	0x000000022f830a70 PredicateExpression.convertToExpressionOrPredicate(state:) + 724 (FetchDescriptor.swift:203)
5   SwiftData                     	0x000000022f831874 PredicateExpression.convertToExpression(state:) + 36 (FetchDescriptor.swift:217)
6   SwiftData                     	0x000000022f83b6c8 PredicateExpressions.Equal.convert(state:) + 328
7   SwiftData                     	0x000000022f8360ec protocol witness for ConvertibleExpression.convert(state:) in conformance PredicateExpressions.Equal<A, B> + 64 (<compiler-generated>:0)
8   SwiftData                     	0x000000022f830a70 PredicateExpression.convertToExpressionOrPredicate(state:) + 724 (FetchDescriptor.swift:203)
9   SwiftData                     	0x000000022f82fd60 PredicateExpression.convertToPredicate(state:) + 28 (FetchDescriptor.swift:224)
10  SwiftData                     	0x000000022f82edb4 nsPredicate<A>(for:) + 956 (FetchDescriptor.swift:88)
11  SwiftData                     	0x000000022f807c2c ModelContext.delete<A>(model:where:includeSubclasses:) + 596 (ModelContext.swift:1846)
12  SwiftData                     	0x000000022f81994c dispatch thunk of ModelContext.delete<A>(model:where:includeSubclasses:) + 56

Any luck with that?

I'm facing the same error.

SwiftData crash: PersistentModel.keyPathToString(keypath:)
 
 
Q