realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RealmSet contains fails with unmanaged object

clementetb opened this issue · comments

Invoking RealmSet<RealmObject>.contains on a managed set passing an unmanaged Realm value would result in the following exception:

IllegalStateException: Cannot modify managed objects outside of a write transaction

The exception is a bit odd, how come we modify objects during the contains?

    @Test
    fun containsFailWith() {
        val unmanaged = RealmSetContainer()
        val managed = realm.writeBlocking {
            copyToRealm(
                RealmSetContainer().apply {
                    objectSetField.add(RealmSetContainer())
                }
            )
        }
        managed.objectSetField.contains(unmanaged)
    }

This is fixed in https://github.com/realm/realm-kotlin/tree/next-major as part of the Collections in mixed-implmentation. Previous issue was #1488. It required quite some changes throughout the operator-infrastructure so don't think it is worth fixing in isolation.