Closed DmytroTols closed 3 months ago
➤ PM Bot commented:
Jira ticket: RKOTLIN-1117
Hi @DmytroTols. Realm's internal storage type for integral properties are Long
and we don't differentiate between the various sizes in the file (though we only use the necessary bits required to hold the smaller types). The truncation to the smaller types , e.g. Int
are done in the model class' accessors, which are not in effect for dynamic objects. So you should just use
newObject?.set("legs", oldObject.getValue("legs", Long::class))
Thank you for quick response
How frequently does the bug occur?
Always
Description
In my database when i have Int variable in my RealmObject, when i migrate I want to parse different value if some value is already given in old database version.
When i try to access the value or to set the value as Int i get error: java.lang.IllegalArgumentException: Trying to access property 'Dog.legs' as type: 'class kotlin.Int' but actual schema type is 'class kotlin.Long'
If i redeclare it as a Long, everything works good, but why should i declare it as Long since in my database i declare it as Int, here small snippet, will also attach Demo and Log output:
My object:
open class Dog() : RealmObject { @PrimaryKey var type: String = "TEST DOG" var legs: Int = 0 }
When i try doing something like this, access variables as Int:
migrationContext.enumerate("Dog") { oldObject, newObject -> newObject?.set("legs", oldObject.getValue("legs", Int::class)) }
I get error that i declared above, here is stackTrace
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
Initialize database with 1 version, after running app once, redeclare database version and migrate to next version, while migrating access Int variable as Int and not as Long, when migration will run issue will apear
Version
1.15.0
What Atlas App Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Android 10
Build environment
Android Studio version: ... Android Build Tools version: ... Gradle version: ...