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

RealmObject equals are probably not correct #1097

Closed
cmelchior opened this issue Oct 30, 2022 · 4 comments · Fixed by #1480
Closed

RealmObject equals are probably not correct #1097

cmelchior opened this issue Oct 30, 2022 · 4 comments · Fixed by #1480
Assignees

Comments

@cmelchior
Copy link
Contributor

cmelchior commented Oct 30, 2022

When reading objects from Realm, we use their default equals implementation, which compares by memory reference. This means that the following behavior can be observed:

realm.writeBlocking {
            val result = copyToRealm(sample)
            val obj1 = result.nullableObject
            val obj2 = result.nullableObject
            assertNotEquals(obj1, obj2) // Managed objects use default `equals`, i.e. compare mem ref. 
}This is probably not what you would expect, and we should consider if managed objects should have their own equals implementation that compare <ClassKey,ObjectKey,Version> instead. It would probably have to be implemented in the Compiler Plugin so we can avoid generating it if users have their own equals method.

We should also take into account RealmAny instances containing objects.

@tarasmorskyi-mediamonks

Any update on this? Is currently the only option is to compare value by value aka deepEquals?

@tarasmorskyi-mediamonks

@cmelchior tagging you as reporter

@cmelchior
Copy link
Contributor Author

Hi @tarasmorskyi-mediamonks. Unfortunately, the work-around right now is to use deepEquals. We will be looking into fixing this shortly because this also effects things like Lists, Sets and Maps.

edualonso pushed a commit that referenced this issue Feb 27, 2023
@edualonso edualonso mentioned this issue Feb 27, 2023
18 tasks
@cmelchior cmelchior self-assigned this Apr 19, 2023
@cmelchior
Copy link
Contributor Author

It appears this issue fell through the cracks and should be fixed soon.

@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.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants