realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

RealmSet contains fails with unmanaged object

Open clementetb opened this issue 1 year ago • 1 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)
    }

clementetb avatar Dec 21 '23 12:12 clementetb

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

rorbech avatar Dec 21 '23 12:12 rorbech

Fixed by #1716

rorbech avatar Apr 04 '24 12:04 rorbech