realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
967 stars 61 forks source link

Unable to migrate RealmDictionary #1805

Open MarzNovi opened 4 months ago

MarzNovi commented 4 months ago

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

sync-by-unito[bot] commented 4 months ago

➤ PM Bot commented:

Jira ticket: RKOTLIN-1110

MarzNovi commented 4 months ago

Please find here the repro demos:

https://drive.google.com/drive/folders/1tNkuL_JZbNXGZa9LuYMAOc_js_a3MyCz?usp=sharing

Usage:

  1. Run the JavaRealm app first
  2. Notice the data output
  3. Run the KotlinRealm app
  4. Notice that the data is printed at first, but after the migration it is null