SwiftData/ModelCoders.swift:1762: Fatal error: Passed nil for a non-optional keypath

I updated today at Xcode 16 beta 6, and my app using SwiftData on iOS 18 (beta 6) is getting now this new error when saving the model in the modelContext.

I don't understand if it is a regression introduced in the beta 6 or if it is enforced something that previously wasn't.

It seems to be always referred to the ID property, for example:

SwiftData/ModelCoders.swift:1762: Fatal error: Passed nil for a non-optional keypath \MyModel.id

In this case (and in most of the cases in my models) the ID is defined as following

    @Attribute(.unique)
    public var id: UUID

I also tried to add the initialization inline, but didn't help

    @Attribute(.unique)
    public var id: UUID = .init()

I also tried to remove the @Attribute(.unique), didn't help as well.

Does any of you have the same issue?

Same on iOS 18 Beta 7.

The "funny" thing is that it crashes on the try, the error is not catched.

          ...
          try context.save() <<< Crash
                
            } catch {
                print(error)
            }

Same here.

I filed feedback for either this or a similar issue FB15170769 - I reproduced the same Fatal Error but there's no save needed, it happens when a FetchedResultCollection is passed to a SwiftUI List()

Any information about this? As Juan said, this bug happens if ANY parameter is required.

Do you have any attribute that uses an enum? I had the same issue and solved it by setting the attribute that is defined to an optional enum.

SwiftData/ModelCoders.swift:1762: Fatal error: Passed nil for a non-optional keypath
 
 
Q