App crashes with "Can't set object of type"

Hi all! This error has been reported in GitHub too, but it seems there are still no solutions.
As the title states, app crashes when trying to update an object that has another realm object as a property.

In my case I have

class ServiceEntity: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var name: String
    @Persisted var iconName: String
    @Persisted var mainColor: String
    @Persisted var secondaryColor: String
    @Persisted var _partitionValue: String = AppInfo.partitionValue
    @Persisted var serviceType: ServiceType?
    
    convenience init(name: String, mainColor: String, secondaryColor: String, iconName: String, serviceType: ServiceType) {
        self.init()
        self.name = name
        self.mainColor = mainColor
        self.secondaryColor = secondaryColor
        self.iconName = iconName
        self.serviceType = serviceType
    }
}

and

class ServiceType: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var name: String
    @Persisted var iconName: String
    @Persisted var mainColor: String
    @Persisted var secondaryColor: String
    @Persisted var _partitionValue: String = AppInfo.partitionValue
    
    convenience init(name: String, mainColor: String, secondaryColor: String, iconName: String) {
        self.init()
        self.name = name
        self.mainColor = mainColor
        self.secondaryColor = secondaryColor
        self.iconName = iconName
    }
}

Creating a new ServiceEntity object and setting serviceType property works flawlessly. Updating a ServiceEntity object modifying the serviceType property always crashes with

*** Terminating app due to uncaught exception ‘RLMException’, reason: ‘Can’t set object of type ‘ServiceType’ to property of type ‘ServiceType’’

It always happens :confused:

I forgot to add some details:

  • App is in SwiftUI
  • serviceType property is set opening a sheet containing a list of ServiceType objects and tapping on one of them
  • service object is declared as @ObservedRealmObject var service: ServiceEntity
  • App is compiled with Xcode 14 beta 5 on iOS16