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

Unable to migrate RealmDictionary

Open MarzNovi opened this issue 1 year ago • 2 comments

How frequently does the bug occur?

Always

Description

Hello,

We are facing an error when running a migration from realm 10.9.0 to realm-kotlin 1.15.0

The RealmObject looks like this:

@RealmClass(embedded = true)
open class ExampleEntity() : RealmObject() {

    var data: RealmDictionary<String> = RealmDictionary()

}

And the migration script just tries to set the data to the new object like so:

migrationContext.enumerate("ExampleEntity") { oldObject, newObject ->

    val data = oldObject.getNullableValueDictionary("data", String::class)
    println("Data: $data")

    newObject?.run {
        set("data", data)
    }
}

When the migration script runs, we can verify that the oldObject data printed out is correct, however in the resulting database, data value appears to be an empty object and we get a type error triggered by the line that attempts to set the data: set("data", data)

Stacktrace & log output

Trying to access property 'ExampleEntity.data' as type: 'RealmDictionary<class io.realm.kotlin.internal.ManagedRealmDictionary>' but actual schema type is 'RealmDictionary<class kotlin.String>'

Can you reproduce the bug?

Yes, a related demo will be attached shortly

Reproduction Steps

  1. Build project with Java version of the database
  2. Run migration to Kotlin version
  3. Notice the error on Logcat

Version

1.15.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

Android API 8+

Build environment

Android Studio version: Android Studio Koala | 2024.1.1 Android Build Tools version: 35 Gradle version: 8.7

MarzNovi avatar Jul 10 '24 16:07 MarzNovi