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

Deleting Non-Optional Frozen RealmObject Crashes #1300

Closed
skresearcher opened this issue Mar 4, 2023 · 3 comments · Fixed by #1304
Closed

Deleting Non-Optional Frozen RealmObject Crashes #1300

skresearcher opened this issue Mar 4, 2023 · 3 comments · Fixed by #1304
Assignees

Comments

@skresearcher
Copy link

skresearcher commented Mar 4, 2023

Hi!

I was looking at the docs for deleting a frozen object, and the example shows how to delete an optional RealmObject, which works fine. If, however, I modify the query to return a non-optional like below:

val sample: Sample = realm.query<Sample>().find().first()

realm.writeBlocking {
    findLatest(sample)?.also { delete(it) }
}

The code crashes with the following error:

java.lang.IllegalStateException: A deleted Realm object cannot be returned from a write transaction.

But if I add any other line (i.e. println or return) in the writeBlocking clause, it deletes the object without erroring out:

realm.writeBlocking {
    findLatest(sample)?.also { delete(it) }
    return@writeBlocking // Replace with anything else
}

Is this the intended behavior when deleting frozen, non-optional RealmObjects?

@sync-by-unito
Copy link

sync-by-unito bot commented Mar 7, 2023

➤ rorbech commented:

From discussions we think that we should just skip freezing invalid objects.

@cmelchior
Copy link
Contributor

A fix has been merged and is available in 1.6.2-SNAPSHOT

@skresearcher
Copy link
Author

Thanks for fixing the issue!

@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

Successfully merging a pull request may close this issue.

2 participants