Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdatePolicy.ALL ignored for internal objects #771

Closed
tarasmorskyi-mediamonks opened this issue Mar 30, 2022 · 2 comments
Closed

UpdatePolicy.ALL ignored for internal objects #771

tarasmorskyi-mediamonks opened this issue Mar 30, 2022 · 2 comments
Assignees

Comments

@tarasmorskyi-mediamonks
Copy link

tarasmorskyi-mediamonks commented Mar 30, 2022

Error is received if some object from internal RealmList already exists in the database. Haven't tried with just object instead of list.
Received error: Object with this primary key already exists.

@cmelchior
Copy link
Contributor

Hi @tarasmorskyi-mediamonks Do you have some sample code that provokes this?

@tarasmorskyi-mediamonks
Copy link
Author

Here is replication of failed scenario. Checked and it fails with the same error:

open class TestEntity : RealmObject {
    @PrimaryKey
    var id: Long = TestIdGenerator.EntityId
    var children: RealmList<TestEntity> = realmListOf()
}

object TestIdGenerator {
    var EntityId: Long = 0
        get() =
            field++
}

suspend fun test() {
            val one = TestEntity()
            val two = TestEntity()
            val three = TestEntity().apply { children = realmListOf(one,two) }
            realm.write {
                val result = kotlin.runCatching {
                    this.copyToRealm(one, MutableRealm.UpdatePolicy.ALL)
                    this.copyToRealm(two, MutableRealm.UpdatePolicy.ALL)
                    this.copyToRealm(three, MutableRealm.UpdatePolicy.ALL)
                }
                result
            }
        }

@rorbech rorbech self-assigned this Mar 31, 2022
@sync-by-unito sync-by-unito bot closed this as completed Mar 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants