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

At times, Realm proxy objects stop providing their data #7840

Closed
mannodermaus opened this issue Aug 10, 2023 · 9 comments · Fixed by #7844
Closed

At times, Realm proxy objects stop providing their data #7840

mannodermaus opened this issue Aug 10, 2023 · 9 comments · Fixed by #7844

Comments

@mannodermaus
Copy link

mannodermaus commented Aug 10, 2023

How frequently does the bug occur?

Sometimes

Description

I apologize for the flaky description, but I haven't been able to get a firm grasp on the situation yet.

Essentially, ever since a few weeks ago, our Android development environment sometimes reaches a state wherein proxy objects returned from Realm queries stop returning their data to the caller, causing weird behaviors to emerge throughout the app that feel like bugs on our end, but aren't. The toString() representation of the proxy objects include all the data, but when reading any of the properties off the proxy, type-dependent empty data (e.g. 0 or "") is returned. Attached is a screenshot of the debugger output – despite the partial obfuscation, the discrepancy between the top line and the properties should be visible.

Screenshot 2023-08-10 at 15 41 32

When this state happens, clearing the build folder of the affected Gradle module and rebuilding from a clean slate resolves the problem for a while. This causes me to think that it is related to incremental builds, but I'm not sure. In the compilation right before the issue happens, we see the transformer's logs like normal, so it doesn't seem like anything is skipped there.

Another note is that the project is also using AGP 8+ and Gradle 8+, so maybe there is some form of missing support here still? 🤔

Any insight is appreciated!

Note

Since turning off incremental compilation via io.realm.disableIncrementalBuilds = true, I haven't seen the issue creep up again. I will let y'all know if this changes, however.

Stacktrace & log output

No response

Can you reproduce the bug?

No

Reproduction Steps

No response

Version

10.16.1

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

macOS Ventura 13.4

Build environment

Android Studio version: 2023.1.1 Canary 15 (Build #AI-231.9225.16.2311.10572941, built on July 28, 2023)
Android Build Tools version: 34.0.0
Android Gradle Plugin version: 8.1.0
Gradle version: 8.2.1

@fanwgwg
Copy link

fanwgwg commented Aug 12, 2023

+1 We've encountered the same situation since roughly a few weeks ago, sometimes it would randomly stop providing data, all filed accessors will return a default value like 0 or null even if the data exists. This only happens in development but not in production, it typically happens after several rounds of rebuild of the project.

@cmelchior
Copy link
Contributor

Hmm, this looks odd. So the debugger output is totally expected. You can see this link for more details: https://www.mongodb.com/docs/realm/sdk/java/test-and-debug/debugging/#android-studio-debugging

Sporadic behavior could point to some problems with incremental compilation that might change the accessors. But it is unclear exactly what could be going on.

You are saying this is happening on AGP8+ with Gradle 8+, which would make sense since Googles Transform APIs changed there, but are you using any other plugins that might modify code? Like Compose, Dagger, etc.?

@fanwgwg
Copy link

fanwgwg commented Aug 16, 2023

For us this happens only after upgrading to AGP8+. Our setup includes Hilt/Dagger for DI.

I tried debugging too similar to what @mannodermaus does, I understand that the debugger output is expected because realm only accesses the field lazily, the weird thing is that when actually accessing the field itself, it's always 0/null/empty string.

@mannodermaus
Copy link
Author

@cmelchior The project does use Compose, but it has done so for a fairly long time without triggering this behavior in the past. Furthermore, we use Moshi code generation via KSP, but that's about it - Dagger is not in use, and neither are there any bytecode manipulation tools (other than Realm, of course).

@tekeroth-snapcode
Copy link

Same issue for me, just detected it; the RealmProxy object shows all values as "default", so null, 0, except for List<>, that contains the objects expected, but also the objects in the lists as "defaulted" everywhere.

@rafiqlightwala
Copy link

Can confirm I faced this exact issue today. Same as all the participants described. gradle 8. and not just debugging, the received properties are null. not using compose.

@mannodermaus
Copy link
Author

mannodermaus commented Aug 31, 2023

Here are some new observations from my side. When this state is reached, the odd behavior of Realm proxies is not limited to read operations. I have seen that if a new element is inserted into a Realm, a new record is inserted into its table, but all the properties are empty.

Furthermore, I have played around with the build settings of our project and found that we are using the Android Cache Fix plugin for Gradle. I've turned that off and haven't seen the issue reappear in a few days. It might be coincidence, but do other commenters here use that same plugin? I'm wondering if it interferes with Realm's incremental bytecode manipulation when using AGP 8 or Gradle 8, so if you do use it, try turning it off for a while and give it another go. Never mind, it happened again. ☹️

@chk2902
Copy link

chk2902 commented Oct 24, 2023

Same here. Cleaning or Rebuilding the project helps for a while, but the problem reappears here after a couple of compilations. Objects not added to the database, default values read from RealmObjects... took me hours to make sure my code was not wrong.

I see it was fixed, but the realm grade plugin I use is still the 10.16.1?

@clementetb
Copy link
Collaborator

@chk2902 The issue was fixed in version 10.16.2. Please update the Realm Gradle plugin to apply the fix.

@sync-by-unito sync-by-unito bot closed this as completed Nov 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 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.

7 participants