-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
3 - M (<= 1 month)
-
4808
-
Not Needed
Expected results
I don't think it should be possible to update a primary key field of an object. So I would expect the C-API to throw an error if doing so. If it should be possible to update it, I would at least expect a check that you are not creating duplicate primary keys when setting it.
Actual Results
In realm-kotlin I am able to define a schema with a primary key and after creating of an instance I am able to update the primary key field even setting it to the same primary key value of an already existing object.
I#### Steps & Code to Reproduce
class PrimaryKeyString : RealmObject { @PrimaryKey var primaryKey: String = Random.nextULong().toString() } realm.writeBlocking { val first = copyToRealm(PrimaryKeyString().apply { primaryKey = PRIMARY_KEY }) val second = copyToRealm(PrimaryKeyString().apply { primaryKey = "Other key" }) // expect update to cause an error assertFailsWith<RuntimeException> { second.primaryKey = PRIMARY_KEY } // eliminating the above assert will render the following to pass, which shows that we end up with two objects both with the same primary key value val objects = objects(PrimaryKeyString::class) assertEquals(2, objects.size) val first2 = objects[0] val second2 = objects[1] assertEquals(objects[0].primaryKey, objects[1].primaryKey) }
Core version
Core version: 10.8.0
- is depended on by
-
RKOTLIN-246 Prevent updates of primary key fields
- Closed