ModelContainer causes errors depending on the order in which configurations are supplied

Dear community,

I am looking for help with an issue that is puzzling me regarding the creation of a SwiftData ModelContainer.

I have a ModelContainer that holds some model types that are stored using two different configurations:

let fullSchema = Schema([TypeA.self, TypeB.self])
let configurationA = ModelConfiguration(schema: Schema([TypeA.self]), url: "url/to/file/in/app-support/dir")
let configurationB = ModelConfiguration(schema: Schema([TypeB.self]), url: "url/to/another/file/in/app-support/dir")
let modelContainer = ModelContainer(for: fullSchema, configurations: configurationA, configurationB) // (1) read on

I add this container to my view hierarchy using the .modelContainer(modelContainer) view modifier. In on of my views of the app I use a @Query to access objects of type TypeB like this.

@Query(sort: \TypeB.someAttribute, order: .reverse) private var arrayOfB: [TypeB]

Accessing the view in my app will cause the app to crash with the error: Thread 1: "NSFetchRequest could not locate an NSEntityDescription for entity name 'TypeB'"

Now, if I reverse the order in which i specify the configuration for the model container in the line marked // (1) above to

let modelContainer = ModelContainer(for: fullSchema, configurations: configurationB, configurationA)

the query resolves successfully without crashes.

I am looking for information on why the order of the configuration might matter and how to fix this behavior.

Please note that because the app is in early development, I do not have objects of type TypeA implemented yet and cannot verify if this behvaior occurrs with these types, too. Edit: This behavior is also true for queries for TypeA. They will not crash the app if the configuration for TypeA is the first configuration passed to the ModelContainer.

This is related to https://developer.apple.com/forums/thread/735268. You should see that only the first configuration is taken into account, which means that trying to Query Type.A will crash if you reverse the order, so it's not really a solution 🫤

ModelContainer causes errors depending on the order in which configurations are supplied
 
 
Q