Crash when injecting partition for @AsyncOpen while passing @ObservedRealmObject

Working in Swift with RealmSync.
Not sure if I implemented this just wrong, but I checked with the guidelines with SwiftUI and can really not find anything that’s off. While passing a @ObservedRealmObject I can no longer inject a partition for @AsyncOpen I try to open in the subview.
The problem is quite complex, so below code should illustrate what I am trying to do. With a similar setup to the one below, the app crashes with following output:

"
terminating with uncaught exception of type realm::MismatchedConfigException: Realm at path ‘/Users/HIDDEN/Library/Developer/CoreSimulator/Devices/HIDDEN-2B56-40D4-B085-39BEC872E347/data/Containers/Data/Application/HIDDEN-623E-4999-AA78-116468126CF5/Documents/mongodb-realm/HIDDEN-HIDDEN/HIDDEN/%22PARTITION%22.realm’ already opened with different partition value.
CoreSimulator 757.5 - Device: iPhone 11 (HIDDEN-2B56-40D4-B085-39BEC872E347) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 11
"

struct View1: View {
    
    @ObservedResults(Example.self) var examples
    
    var someImportantVariable = "123"
    
    var body: some View {
        NavigationView {
            NavigationLink(
                destination:
                    View2(importantExample: examples.first)
                        .environment(\.partitionValue, "session=\(someImportantVariable)"), // realm being opened async, just injecting partition...
                label: {
                    Text("go")
                })
        }
    }
}

struct View2: View {
    
    @ObservedRealmObject var importantExample: Example
    
    @AsyncOpen(appId: "HIDDEN", partitionValue: "", timeout: 4000) var asyncOpen // partition value injected from parent view
    
    var body: some View {
        Text("handling the async open...")
    }
}

Why is that in View2? That looks like View1 is not using Sync but View2 is?

Sorry, should have been more precise: A realm with a different partition is already injected into View1 from its parent, so View1 receives Objects [Example] from which it needs one to set the partition value of the Realm of View2, but also pass along the according object from the Realm of View1. The new realm needs to have a new partition but when passing the object from the Realm of View1, it probably tries to inject the partition into both realms, while it should only inject it into the newly created real. If that makes sense. So the code could be:

struct ContentView: View {
    var body: some View {
        View1()
           .environment(\.realmConfiguration, user.configuration(partitionValue: "somePartition"))
    }
}

Github issue about this: Github issue Link

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.